dongzhu7329 2016-05-11 23:42
浏览 92

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

I am a little new to MySQL and PHP please help me.. I am try to do a web application where users select an ingredient (e.g..chicken) and it will show 11 recipes(I limited my recipes to 11) related to the selected ingredient.. It's working perfectly.. but I want to change it to check box so that users can select multiple ingredients (e.g.. chicken, carrot, butter).. I have no idea how to do it! Please help.. I have my database ready with all the recipes sorted out according to the Ingredient.

here is my code for the one Ingredient..

        <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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
    • ¥20 yolov5自定义Prune报错,如何解决?