我想从<select>
标签中检索一个值到PHP
...这个选定标签中的选项是一个函数,它从一个名为的单独文件PHP
中列出这些选项php
functions.php
请参阅下面的功能functions.php
function list_brand (){
$sql = "SELECT brand FROM laptop
";
$query = mysql_query($sql) or die (mysql_error());
if ($query) {
//echo 'success'; <-- testing the function functinality
while ($query_row = mysql_fetch_assoc($query)) {
$brand = $query_row['brand'];
echo '<option value="brand">'.$brand.'</option>';
}
} else {echo 'fiald if';}
}
以下是选定的标签:
<select id="test" onchange="document.getElementById('text_content').value=this.options[this.selectedIndex].text">
<option value="select">SELECT BRAND</option>
<?php list_brand(); ?>
</select>
<input type="hidden" name="brand_text" id="text_content" value="" />
现在我的问题是我还有另外两个选定的标签,它们应该根据第一个选定标签中的选定选项列出选项,并且它应该列出完整的 SQL 查询
以下是我的完整 html 代码:
<form action="comparison.php" method="GET">
<table width="80%" border="0" align="center" cellpadding="1" cellspacing="2">
<tr>
<td colspan="2">Lap 1</td>
<td colspan="2">Lap 2</td>
</tr>
<tr>
<td width="19%">Brand</td>
<td width="31%"><select><option value="brand1">==SELECT BRAND==</option>
<?php
list_brand();
?>
</select></td>
<td width="19%">Brand</td>
<td width="31%"><select name="brand2"><option value="brand2">==SELECT BRAND==</option>
<?php
list_brand();
?>
</select></td>
</tr>
<tr>
<td width="19">Model</td>
<td width="31"><select><option value="model1">==SELECT MODEL==</option></select></td>
<td width="19">Model</td>
<td width="31"><select><option value="model2">==SELECT MODEL==</option></select></td>
</tr>
<tr>
<td width="19">Partnumber</td>
<td width="31"><select><option value="pn1">==SELECT PARTNUMBER==</option></select></td>
<td width="19">Partnumber</td>
<td width="31"><select><option value="pn2">==SELECT PARTNUMBER==</option></select></td>
</tr>
<tr>
<td height="453" colspan="2"> </td>
<td colspan="2"> </td>
</tr>
</table>
</form>