如何回顯多個結果。目前這顯示配方名稱,但我希望能夠迴應數據庫中的步驟。所以在數據庫中的字段將是第1步。如何從數據庫中回顯多個結果
<?php
if (isset($_POST['search'])) {
$ingredient1 = $_POST['dropdown1'];
$ingredient2 = $_POST['dropdown2'];
$ingredient3 = $_POST['dropdown3'];
$recipes = mysql_query("
SELECT DISTINCT `name`
FROM `recipe` r
INNER JOIN `recipe_ingredients` ri
ON r.id = ri.recipe_id
WHERE ri.ingredient_id IN (".$ingredient1.",".$ingredient2.",".$ingredient3.")
");
echo '<section id="results">';
while ($recipe = mysql_fetch_assoc($recipes)) {
echo $recipe['name'].'<br />';
}
}
echo '</section>';
?>
這引發了一個錯誤。 :PHP解析錯誤:語法錯誤,意外 '',期待在\ PDC3 \網站 ']' \ C \ cupboard2stomach.com \的public_html \上線PHP \ get.php 97
echo $recipe['name'].'<br />';
echo $recipe['step1'].'<br />';
沒有錯誤,但沒有按不顯示結果。
echo $recipe['name','step1'].'<br />';
這是配方表
echo '<section id="results">';
while ($recipe = mysql_fetch_assoc($recipes)) {
echo $recipe['name'].'<br />';
echo $recipe['step1'].':','<br />';
echo $recipe['step2'].':','<br />';
echo $recipe['step3'].':','<br />';
}
}
echo '</section>';
這些都是結果我回來
我在查詢的選擇字段中看不到'step1'列。 – Rikesh 2013-05-04 16:56:17
您需要向我們展示錯誤以及您的mysql表的外觀。 – 2013-05-04 16:57:20
你的SQL查詢似乎只選擇一列 - 'name' – MrVimes 2013-05-04 16:59:00