这是一个配方项目,用户使用表单并输入自己的食谱。我有整个部分的工作。现在我试图从数据库中检索配方的信息并将其显示在页面上。无论如何,这是我现在的代码。来自关联数组的回声特定数据?
<?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”,我试图回显刚才存储在“category_name”中的这个配方的值,这恰好是“none”。我如何在页面上回复“none”这个词?
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" }
}
请让我知道,如果我可以给你任何更多的信息。这是漫长的一天,我可能会错过一些可以帮助你的东西。
哦啧..我没想到它会这么简单。谢谢! – crarls 2014-09-26 04:08:07
很简单! :)干杯 – Rasclatt 2014-09-26 04:08:56
@bansi真正的dat ...他们说。 – Rasclatt 2014-09-26 04:16:33