我试图在下拉列表中打印选定的值,但徒劳无功。我是 php 和 html 的新手,所以这听起来像是一个愚蠢的问题,但请帮帮我!这是我的代码:
echo '<tr><td>Client:</td><td><select name="client_name">';
$sql = mysql_query("SELECT * FROM client");
$s= mysql_query("SELECT project.client_id, client_name, client.client_id FROM client,project where project.client_id=client.client_id AND project_id='$editId'");
// $s2= mysql_fetch_array($s);
while ($row = mysql_fetch_array($sql))
{
while ($s2==mysql_fetch_array($s))
{
if ($row['client_id'] == $s2['client_id'])
$selected = "selected=\"selected\"";
else
$selected = " ";
}
echo '<option value="' . $row['client_id'] . '" ' . ($selected == $row['client_id'] ? ' selected' : '') . '>' . $s2['client_name'] . '</option>';
}
此代码不起作用。请帮帮我!有不同的方法吗?