【发布时间】:2014-09-11 16:08:58
【问题描述】:
我开始使用 php 进行编程,但我有一点疑问。
我正在尝试使用下拉列表中的值搜索数据库。
问题是查询总是使用下拉列表的最后一个值。
有人可以帮我找出错误吗?
为什么研究where子句总是下拉的最后一个值?
代码
<tr><td>Technical:</td><td>
<select>
<?php
$query = "SELECT idTechnical, name FROM technicals";
$result2 = mysql_query($query);
$options="";
while($row=mysql_fetch_array($result2)){
$id=$row["idTechnical"];
$thing=$row["name"];
echo "<OPTION VALUE=$id>$thing</option>";
}
?>
</select>
<?php
if (isset($_POST['Next'])) {
if($_REQUEST['Next']=='Search') {
{
$sql="select idTask, descTask, deadline, idTechnical from tasks where idTechnical = '$id' order by deadline desc";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
}
}
}
?>
我从下拉列表中选择任何值,但只使用子句 where :S 中的最后一个值
【问题讨论】:
-
你的
-
旁注:你应该引用你的变量
echo "<OPTION VALUE=\"$id\">$thing</option>";你可能会得到意想不到的结果。 -
echo '<option VALUE="'.$id.'">'.$thing.'</option>'; -
$id无论如何都未在您的搜索脚本中定义。 -
@LauriOrgla 感谢您的回复。你的建议对我有用。