javascript - Dynamic Select Box Dependent Using MySQL Database
问题描述
I'm developing a website for comparing prices of cars:
The user should enter: Year Make Model
Database Structre & Example:
id -- year -- make -- model
1 2018 Fiat Ponto
2 2018 Seat Leon
3 2017 Hyundai Veloster
So Now I'm displaying Select boxes but I need it to get the Select Box Value Before submitting form.
<div>
<?php
$cars = "SELECT distinct year FROM `cars` ";
$carsResult = mysqli_query($conn, $cars);
?>
<select name="year" class="selectStyle">
<option disabled selected >Year</option>
<?php
if(mysqli_num_rows($carsResult) > 0){
while($row = mysqli_fetch_assoc($carsResult)){
?>
<option id="year" value="<?php echo $row['year']; ?>"><?php echo $row['year']; ?></option>
<?php
}
} else {
?>
<option value="">0 results</option>
<?php
}
?>
</select>
<
<select name="make" class="selectStyle">
<option disabled selected>Make</option>
// Here I need to display more
</select>
</div>
So on the second Select I need to display only for the selected year: "SELECT make FROM cars WHERE year = {users year}" How can i get the user selected year to the sql query?
So after i can check: "SELECT model From cars WHERE year= {users year} AND model = {users model}"
Please help me, I'm tring forever now!
解决方案
推荐阅读
- python-3.x - 气流 {logging_mixin.py:84} 警告 - --- 记录错误 -
- python - 如何检查列表列表是否包含值?
- xamarin.forms - 使用 Prism.Autofac 库 Xamarin .Net Standard 2.0 时 App.Current.MainPage 为空
- html - 向模态窗口添加滚动条
- javascript - localStorage 在 react js chrome 中不起作用
- python - 对本地文件夹中的所有文件重复 BeautifulSoup 抓取
- ethereum - 警告:不推荐使用从地址类型继承的合约成员“余额”。坚固性
- c# - 对有关初始化变量的课程说明感到困惑
- machine-learning - 数据科学:当 csv 文件有数千列时如何处理和清理数据
- pandas - lightgbm 是否按顺序返回预测?