duanjurong1347 2017-04-06 13:11
浏览 52

如何使用PHP中的复选框从MYSQL数据库中检索数据以及如何设置if语句以通过比较为您提供特定结果?

Before I start on this things and I would like to inform that I have tried to find in the web, youtube and books and it seems I don't get a clue for what I am exactly trying to do.

The main feature of this page is the following as example: a MySQL database in XAMPP and a HTML page with PHP on it. My PHP code conects to the DB and then I have created 3 checkboxes -

  • 1 - MOUSE
  • 2 - Dog
  • 3 - Tiger

( This things will be the checkboxes options. with an input button (to retrieve the info)

If you select checkbox 1 the PHP code should call the Table animals and give you as result MOUSE

But I want that if user select Mouse and DOG, retrieve the fastest animal in this case will be Checkbox 2: Or if user select 3 of them gives you as result number 3 (Tiger.)

I being watching tutorials and so on an the retrieve I got it but only for the HTML part even I can connect to the DB, the questions will be

How do I set first the Checkboxes? How do I call the database to each of this checkboxes? Which comparison statement do I need to use in order to give me the desired logic?

html>  
      <head>  
           <title>Fastest animal selection</title> 
      </head>  
      <body>  
        <div class="container box">
          <h3 align="center">Fastest animal selection</h3><br />
          <h4>Please Select your Animal.</h4><br />  
          <form method="post">
           <p><input type="checkbox" name="animal[]" value="MOUSE" /> MOUSE</p>
           <p><input type="checkbox" name="animal[]" value="DOG" /> DOG</p>
           <p><input type="checkbox" name="animal[]" value="TIGER" /> TIGER</p>
           <p><input type="submit" name="submit" class="btn btn-info" value="Get fastest animal" /></p>
          </form>
          <?php
         if(isset($_POST["submit"]))
          {
           $for_query = '';
           if(!empty($_POST["animal"]))
           {
            foreach($_POST["animal"] as $animal)
            {
             echo '<p>'.$animal.'</P>';
             }
             }
             else
                { 
            echo "<label class='text-danger'>* Please select at least one animal.</label>";
            }
            }
            ?>
            </div>  
      </body>  
 </html>

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度