php获取用户下拉列表选择
我如何为每个用户选择下拉菜单。
user table
------------
id job
1 1
2 2
job table
----------
id name
1 Doctor
2 Sales
$q = $db->query("SELECT * FROM affiliate LEFT JOIN user ON user.job = affiliate.id_affiliate");
while($r = $q->fetch_array()) :
if($r['id_user'] == $_SESSION['id_user'] && $r['job'] == $r['id_affiliate']) {
echo '<option selected value="'.$r['id_affiliate'].'">'.$r['org'].'</option>';
} else {
echo '<option value="'.$r['id_affiliate'].'">'.$r['org'].'</option>';
}
endwhile;
how do i get dropdown selected for each user.
user table
------------
id job
1 1
2 2
job table
----------
id name
1 Doctor
2 Sales
$q = $db->query("SELECT * FROM affiliate LEFT JOIN user ON user.job = affiliate.id_affiliate");
while($r = $q->fetch_array()) :
if($r['id_user'] == $_SESSION['id_user'] && $r['job'] == $r['id_affiliate']) {
echo '<option selected value="'.$r['id_affiliate'].'">'.$r['org'].'</option>';
} else {
echo '<option value="'.$r['id_affiliate'].'">'.$r['org'].'</option>';
}
endwhile;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
selected="selected"
或只是selected
应该正常工作。如果不是,则说明您的 if 语句有问题。一种简单的方法是回显 if 语句的内容,如下所示:注意!回显通常应该在选择开放标签之外完成,只需将以下内容粘贴到选择开放标签之外,但就在查询之后。
您现在可以检查这些值是否确实匹配。如果没有,那就是你的问题。
selected="selected"
or justselected
should normally work. If not there is a problem with your if statement. One simple way is to echo out the content of the if statement like this:note!! the echo should normally be done outside the select open tag, just paste the following outside the select open tag but just after your query.
you can now check if the values actually match. if not then there is your problem.
修改以下内容怎么样...
不确定这是否重要,但我在选项末尾选择了
选择
。How about modifying the following ...
Not sure if it matters, but I have
selected
at the end of my option.