新手在这里...我试图从这里调整我的代码
该列表已正确填充,但我无法对其进行预选。我究竟做错了什么?提前致谢!
$q = "SELECT cat_id FROM category_user WHERE cat_id=$d";
while ($row = mysqli_fetch_array($q)) {
$cat = (int)$row['cat_id'];
}
$q = "SELECT cat_id, cat FROM category";
$r = mysqli_query ($dbc, $q);
if (mysqli_num_rows($r)> 0) {
while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) {
echo "<option value=\"$row[0]\"";
$selected = '';
$cid=(int)$row[0];
if ($cid=$cat) {
$selected='selected="selected"';
echo $selected;
echo ">$row[1]</option>\n";
}else{
//Check for stickyness
if (isset($_POST['category'])&&($_POST['category']== $row[0]))
echo 'selected="selected"';
echo ">$row[1]</option>\n";
}
}
}
category
---------------
|cat_id | cat |
---------------
category_user
-------------------------
|cu_id | user_id | cat_id|
-------------------------