我一直在一个项目上工作了几个星期,用户选择一组成分,它提取出有成分的食谱,但现在我有一个页面显示食谱,我希望用户能够点击一个特定的食谱,并被引导到一个页面,显示该食谱和它的说明。使用会话ID来抓取数据
我需要使用会话ID吗?
这会显示结果和必须按下的按钮才能进入配方说明页面。
这是您定向到的页面,它将显示食谱图像,名称,配料和说明。
<?php
if (isset($_POST['search'])) {
$ingredient1 = mysql_real_escape_String ($_POST['dropdown1']);
$ingredient2 = mysql_real_escape_String ($_POST['dropdown2']);
$ingredient3 = mysql_real_escape_String ($_POST['dropdown3']);
$recipes = mysql_query("
SELECT DISTINCT `name`, `step1`, `step2`, `step3`, `image`, `reference`
FROM `recipe` r
INNER JOIN `recipe_ingredients` ri
ON r.id = ri.recipe_id
WHERE ri.ingredient_id IN (".$ingredient1.",".$ingredient2.",".$ingredient3.")
");
while ($recipe = mysql_fetch_assoc($recipes)) {
echo '<section id="row">';
echo '<br />';
echo $recipe['name'].'<br />';
echo '<br />';
echo "<img src=\"{$recipe['image']}\" height=100 width=100 /><br />";
echo '<form action="recipe.php">';
echo '<input id="search" name="Look" type="Submit" value="Look" >';
echo '</form>';
echo '<br />';
echo 'You will Need: ';
echo '<br />';
echo '</section>';
//echo 'Step 1: ';
//echo $recipe['step1'].'<br />';
//echo '<br />';
//echo 'Step 2: ';
//echo $recipe['step2'].'<br />';
//echo '<br />';
//echo 'Step 3: ';
//echo $recipe['step3'].'<br />';
//echo '<br />';
//echo '<br />';
//echo '<a href="http://'.$recipe['reference'].'">'.$recipe['reference'].'</a>';
//echo '</li>';
//echo '</ul>';
}
}
?>
这是抓住从数据库中信息的PHP。
是您的实际问题“我需要使用会话ID吗?” – sircapsalot 2013-05-07 19:13:59
@sircapsalot我想知道这是否是完成此操作的最佳方法。 – 2013-05-07 19:16:30
从表格中提取配方'id'以及步骤,或者使'Look'按钮成为一个链接(例如到'recipe.php?id = <?php echo $ recipe ['id'];?>')或者保留一个表单并添加一个隐藏字段:' />”'。根据您的表单方法('get'或'post'),您可以在_recipe.php_中以'$ _GET ['id']'或'$ _POST ['id']'的身份访问id。 – Lukas 2013-05-07 19:22:05