有人可以帮助我如何使用(php/js 或 jquery)获取它吗?我还是初学者。
我在 mysql 中有一个表,其中包含其他内容(在检查数据库之前我不知道)
- 公司名称(例如 Abc、Def...)
- 年份
- 月
- 以及每个月不同月份的一些数据
我需要创建一个表单,在第一个选择字段中加载可用的公司名称。当用户选择其中之一(Abc)时,它应该仅显示该公司填充的适当年份(2000、2008、2012)等(刚刚填充的选定年份)月)。
我已经完成了第一部分(如下),但是如果我在不检查数据库的情况下不知道可能的组合,如何处理不同公司的不同选择。
<?php
echo "Select company: <select name=\"company\">";
$con=connect();
$result = mysqli_query($con,"SELECT * FROM Company");
while($row = mysqli_fetch_array($result)) {
echo "<option value=\"".$row['Name']."\">".$row['Name']."</option>";
}
mysqli_close($con);
echo "</select><br>";
?>
最佳答案
in order to do that you need to use Ajax , suppose the ajax file is relatedYears.php
in relatedYears.php, write the following code
<?php
$con=connect();
$result="";
//this is the company name sent by url using ajax in the main page
$company_name= $_GET['company_name'];
$query= "SELECT years FROM COMPANY WHERE company = $company_name";
$x=mysql_query($query) or die('error query');
$years=array();
while($row=mysql_fetch_row($x))
$years[]= $row[0];
foreach($years as $year)
$results .= "<option value='".$year."'>".$year."</option>";
echo $results;
?>
关于php - 根据之前的选择以及数据库中的值创建多个选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26490593/