douyu3145 2017-04-05 11:15
浏览 61
已采纳

HTML / PHP / SQL - 在选定的下拉选项中显示与sql条目相关的信息

So basically, if you didn't understand the question, I have a dropdown menu with car brands (TABLE BRANDS), and when you select a certain option like "Volkswagen" it should display information about car models that are related to the brand "Volkswagen". The car models are in a table called CARS and for example when you select "Volkswagen", below it should display "Polo", "Golf" etc (every entry that is connected with the foreign key brand_id which is located in CARS). How can I make this happen ? Here's where I've got so far:

<?php
                    $sql = "SELECT brands.name, cars.id, cars.model, cars.mileage, cars.color FROM brands, cars WHERE brands.id = cars.brand_id ORDER BY cars.model DESC, brands.name;";
                    $result = $mysqli->query($sql);

                    $sql1 = "SELECT id, name FROM brands";
                    $result1 = $mysqli->query($sql1);

                ?>


<select>
           <?php 
            while ($row = mysqli_fetch_array($result1))
            {
              echo '<option value="'. $row['id'] .'">'. $row['name'] .'</option>';
            }
            ?>
            </select>
  • 写回答

1条回答 默认 最新

  • dqwn64004 2017-04-05 11:21
    关注

    The code is almost right. You should use the dropdown in a form and submit it to another file or php page. On another page, you can use the php code and process the result over there. Get the input from dropdown and submit it to php page.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题