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:

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

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


            while ($row = mysqli_fetch_array($result1))
              echo '<option value="'. $row['id'] .'">'. $row['name'] .'</option>';
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.

    点赞 打赏 评论

相关推荐 更多相似问题