我有3个链选择框,它从表中的同一行数据返回三个值:$ drop,$ drop_2和$ drop_3,我想运行一个mysql查询从该行的另一列返回一个值在表中。我可以直接将值“回显”到页面,但是我想使用数组值然后在“while”循环中从不同的表生成匹配结果。我有以下设置,如果有人能告诉我它为什么不起作用,我将非常感谢!
<h1>Search Results</h1>
<table>
<tr>
<th>Name</th>
<th>Number</th>
<th>Description</th>
</tr>
<?php
$search_results = mysql_query("SELECT id_sensor FROM vehicles_new WHERE make='$drop' AND model='$drop_2' AND year='$drop_3'");
while($result = mysql_fetch_array($search_results)){
echo $result['id_sensor']; //This is displaying the value I need to use in the next query
?>
<?php
$sql = mysql_query("SELECT * FROM products WHERE id='$result'");
while($row = mysql_fetch_assoc($sql)){
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['part_id']; ?></td>
<td><?php echo $row['description']; ?></td>
</tr>
<?php
}
?>
<?php
}
?>
</table>
提前谢谢,乔
答案 0 :(得分:2)
更改此
$sql = mysql_query("SELECT * FROM products WHERE id='$result'");
到这个
$sql = mysql_query("SELECT * FROM products WHERE id='" . $result['id_sensor'] . "'");