设置类='选定'在多个选项标签中(列表/菜单)
抱歉,我想问一个新手问题:)
我有这样的PHP脚本:
<select id="member">
<?php
$sql = " select id,name from member order by name ";
$query = mysql_query($sql);
while($row=mysql_fetch_array($query))
{
?>
<option value="<?php echo $row["id"]; ?>"><?php echo $row["name"]; ?></option>
<?php
}
?>
</select>
然后结果将生成像这样的html
<select id="member">
<option value="1">Jon Skeet</option>
<option value="2">Marc Gravell</option>
<option value="3">Darin Dimitrov</option>
</select>
我的问题是,实际上我在mysql中有2个表,第一个是member表,第二个member_invited表。
在成员表中:
id | 姓名
---------------
00 | 00乔恩·斯基特
01 |马克·格拉维尔
02 | Darin Dimitrov
然后在 member_invited 表中:
id | 姓名
---------------
00 | 00乔恩·斯基特
02 | Darin Dimitrov
在这两个表中 我想这样列出我的清单:
(查看成员邀请的选项标签中的 class="selected")
<select id="member">
<option value="1">Jon Skeet</option>
<option value="2" class="selected">Marc Gravell</option>
<option value="3" class="selected">Darin Dimitrov</option>
</select>
请随意使用 javascript 或 jquery,或者也许我可以仅使用 PHP 来解决它?
非常感谢:)
Sorry, I want to ask a newbie question :)
I have PHP scripts like this :
<select id="member">
<?php
$sql = " select id,name from member order by name ";
$query = mysql_query($sql);
while($row=mysql_fetch_array($query))
{
?>
<option value="<?php echo $row["id"]; ?>"><?php echo $row["name"]; ?></option>
<?php
}
?>
</select>
then the result will be generating html like this
<select id="member">
<option value="1">Jon Skeet</option>
<option value="2">Marc Gravell</option>
<option value="3">Darin Dimitrov</option>
</select>
my question is, actually I have 2 tables in mysql, first is member table and second member_invited table.
in member table:
id | name
---------------
00 | Jon Skeet
01 | Marc Gravell
02 | Darin Dimitrov
then in member_invited table:
id | name
---------------
00 | Jon Skeet
02 | Darin Dimitrov
within this two table
I want to make my list like this:
(look at class="selected" is in option tag that member has invited)
<select id="member">
<option value="1">Jon Skeet</option>
<option value="2" class="selected">Marc Gravell</option>
<option value="3" class="selected">Darin Dimitrov</option>
</select>
please feel free to using javascript or jquery,, or maybe I can solve it just by using PHP ?
many thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须在 MySQL 中连接到
member_invited
表,然后扩展有关结果集中的is_invited
标志的 while 循环you have to do it in MySQL with a join to
member_invited
table and then extend your while loop regardingis_invited
flag from resultset尝试这样的事情
Try something like this
您可能想使用类似的方法来启用多重选择:
http://www.w3schools.com/ Tags/att_select_multiple.asp
而且在服务器端做你想做的事更聪明......
You probably want to use something like this to enable multiple selection :
http://www.w3schools.com/tags/att_select_multiple.asp
And it's more clever to do what you want server-side...