从关联数组中回收数据? [英] Echo data from an assoc array?

查看:65
本文介绍了从关联数组中回收数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个允许用户创建新配方的主表单。表单成功地将输入保存到正确的数据库表。



我有一个页面,其中包含已创建的每个食谱的链接。我现在需要帮助的是在点击该食谱的链接时显示每个食谱的信息。如何从表单提交的所有不同表格中选择相关数据?



这是我目前使用的代码:



I have a master form that allows a user to create a new recipe. The form successfully saves the inputs to the correct database tables.

I have a page with a link to each of the recipes already created. What I need help with now is displaying each recipe's information when that recipe's link is clicked. How do I select the relevant data from ALL of the different tables that the form submitted to?

This is the code that I am working with so far:

<?php
include_once('includes/connection.php');
include_once('includes/recipe.php');
$recipe = new Recipe;

if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $basic_data = $recipe->fetch_data($id);

    $sql1 = $pdo->prepare("SELECT recipes.*, categories.* FROM recipes 
      INNER JOIN categories 
      ON (recipes.category_ID = categories.category_ID) 
      WHERE recipes.recipe_id = ?");
    $sql1->bindValue(1, $id);
    $sql1->execute();

    $results1 = $sql1->execute(); 
    echo $results1 = $sql1->fetchAll(PDO::FETCH_ASSOC);
    var_dump($results1);
?>





上面的代码回显了下面显示的内容,但我不知道如何使用/控制数据回应我想要的。在这种情况下,我专注于category_name。因此,我需要回答这个具体的食谱是'无',因为这个食谱没有归入特定类别。





The code above echos what is shown below, but I have no idea how to use/control that data to echo what I want. In this case, I'm focusing on the category_name. So what I need to have echoed for this specific recipe is 'none' since this recipe is not filed into a specific category.

Arrayarray(1) { [0]=> array(15) { ["recipe_ID"]=> string(1) "1" ["recipe_name"]=> string(20) "English Muffin Pizza" ["category_ID"]=> string(1) "1" ["servings_ID"]=> string(2) "13" ["prep_hours"]=> string(1) "0" ["prep_minutes"]=> string(2) "20" ["cook_hours"]=> string(1) "0" ["cook_minutes"]=> string(2) "10" ["oven_temp"]=> string(3) "350" ["directions"]=> string(402) "These are the directions." ["extra_comments"]=> string(37) "This is a short extra comment." ["recipe_favorite"]=> string(1) "1" ["recipe_photo"]=> string(0) "" ["created"]=> string(19) "2014-09-20 10:22:39" ["category_name"]=> string(4) "none" } }





如果我能为您提供任何其他信息,请与我们联系。我在我的智慧结束,我整天都在努力。我几乎停留在这一点上,所以我以开放的心态来到这里!



Please let me know if I can supply you with any other information. I'm at my wits end here and I've been working on this all day. I'm pretty much stuck at this point, so I'm coming in here with an open mind!

推荐答案

recipe = new Recipe;

if(isset(
recipe = new Recipe; if (isset(


_GET ['id'])){
_GET['id'])) {


id =


这篇关于从关联数组中回收数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆