如何使用PHP从MySQL数据库中检索多个复选框选择的数据?

时间:2016-05-11 23:42:19

标签: php html mysql css

我对MySQL和PHP有点新意请帮助我..我尝试做一个用户选择一种成分(例如.chicken)的网络应用程序,它会显示11个食谱(我限制我的食谱到11)相关选择的成分..它完美地工作..但我想将它更改为复选框,以便用户可以选择多种成分(例如鸡肉,胡萝卜,黄油)..我不知道该怎么做!请帮忙..我已经准备好了我的数据库,并根据成分整理了所有食谱。

这是我的一个成分的代码..

        <div class="maindiv">
        <div class="divA">
        <div class="title">

</div>
<div class="divB">
<div class="divD">
<p>Click On Menu</p>
<?php
 $connection = mysql_connect("localhost", "root", "");  
 $db = mysql_select_db("SBI", $connection); 

$query = mysql_query("select * from recipes", $connection);
while ($row = mysql_fetch_array($query)) {
echo  "<b><a href=\"CookWhatLahSBIBefore.php?id={$row['id']}\">        
{$row['name']}</a></b>";

}
?>
</div>
<?php
if  (isset($_GET['id'])) {
$id = $_GET['id'];

$query1 = mysql_query("select * from recipes where id=$id", $connection);

while (  $row1 = mysql_fetch_array($query1))  {
?>
<div class="form">
<h2>---You can cook..---</h2>

<span  style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Name:</span> <?php echo $row1['recipename']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Ingredients:</span> <?php echo  $row1['ingredients']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Recipe:</span> <?php echo $row1['recipe']; ?><br><br><br>

<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Name:</span> <?php echo $row1['recipename1']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Ingredients:</span> <?php echo $row1['ingredients1']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Recipe:</span> <?php echo $row1['recipe1']; ?><br><br><br>

    <span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Name:</span> <?php echo $row1['recipename2']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Ingredients:</span> <?php echo $row1['ingredients2']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Recipe:</span> <?php echo $row1['recipe2']; ?><br><br><br>

  <span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Name:</span> <?php echo $row1['recipename3']; ?><br><br>
  <span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Ingredients:</span> <?php echo $row1['ingredients3']; ?><br><br>
 <span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Recipe:</span> <?php echo $row1['recipe3']; ?><br><br>

   <span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Name:</span> <?php echo $row1['recipename4']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Ingredients:</span> <?php echo $row1['ingredients4']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Recipe:</span> <?php echo $row1['recipe4']; ?><br><br><br>

    <span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Name:</span> <?php echo $row1['recipename5']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Ingredients:</span> <?php echo $row1['ingredients5']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Recipe:</span> <?php echo $row1['recipe5']; ?><br><br><br>

    <span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Name:</span> <?php echo $row1['recipename6']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Ingredients:</span> <?php echo $row1['ingredients6']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Recipe:</span> <?php echo $row1['recipe6']; ?><br><br><br>

    <span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Name:</span> <?php echo $row1['recipename7']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Ingredients:</span> <?php echo $row1['ingredients7']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Recipe:</span> <?php echo $row1['recipe7']; ?><br><br><br>

    <span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Name:</span> <?php echo $row1['recipename8']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Ingredients:</span> <?php echo $row1['ingredients8']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Recipe:</span> <?php echo $row1['recipe8']; ?><br><br><br>

    <span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Name:</span> <?php echo $row1['recipename9']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Ingredients:</span> <?php echo $row1['ingredients9']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Recipe:</span> <?php echo $row1['recipe9']; ?><br><br><br>

    <span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Name:</span> <?php echo $row1['recipename10']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;"> Ingredients:</span> <?php echo $row1['ingredients10']; ?><br><br>
<span style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Recipe:</span> <?php echo $row1['recipe10']; ?><br><br><br>

 </div>
<?php
}
}
?>




</div>

</div>
</div>

SQL database Do you mean like this?

0 个答案:

没有答案