列表框应该下拉
对每一个人 我的数据库中有一些值,我想用复选框显示它们。 当我单击按钮时应该显示这些值。这不应该出现在组合框中。 因为我想一次发布多个值。 请帮忙解答谢谢
<?php
$womenlist=mysql_query("select * from tbl_cycleduraion where user_id=$_SESSION[user_id]");
$gs=0;
while($girlslist=mysql_fetch_array($womenlist))
{
$gs++;
?>
<li style="background-color:#CCC; width:150px;"><label for="chk1"><input type="checkbox" name="chk_<?php echo $gs?>" id="chk<?php echo $gs?>" value="<?php echo $girlslist['calName'];?>" <?php if($_REQUEST['chk_'.$gs]==$girlslist['calName']){?> checked="checked"<?php }?>><?php echo $girlslist['calName']." ".$girlslist['calDesc']; ?> </label></li>
<?php }?>
to every one
I have some values in my data base i Want to display them with check boxes.
those values should be display when i click at the button. This should not in combo box.
because I want to post multiple values at one time.
Please help with thanks
<?php
$womenlist=mysql_query("select * from tbl_cycleduraion where user_id=$_SESSION[user_id]");
$gs=0;
while($girlslist=mysql_fetch_array($womenlist))
{
$gs++;
?>
<li style="background-color:#CCC; width:150px;"><label for="chk1"><input type="checkbox" name="chk_<?php echo $gs?>" id="chk<?php echo $gs?>" value="<?php echo $girlslist['calName'];?>" <?php if($_REQUEST['chk_'.$gs]==$girlslist['calName']){?> checked="checked"<?php }?>><?php echo $girlslist['calName']." ".$girlslist['calDesc']; ?> </label></li>
<?php }?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以限制查询中的列数(不是
SELECT * ...
)。您已将放入
内。
的
for=""
属性被硬编码为chk1
。您可以取出上的内联
style=""
并将其放入样式表中。我已经“整理”了一下(未经测试):You could limit the number of columns in your query (not
SELECT * ...
). You've put the<input>
inside the<label>
. The<label>
'sfor=""
attribute is hardcoded aschk1
. You could take out the inlinestyle=""
on the<li>
and put it into a stylesheet. I've "tidied" it up a bit (untested):不完全确定您在这里要求什么(因为看起来您已经使用复选框进行了此操作),但实际上您可以使用选择框发布多个值。您只需使用
multiple
属性,并将名称指定为带有方括号的数组:如果您使用此方式发布表单,请选择 Woman 2 & 3、
var_dump($_POST);
产生:或者,如果您希望复选框的值以类似的方式显示,请更改它们,使它们都具有相同的
名称
,但末尾带有方括号。此 HTML 将生成类似的 POST 数据:因此,要使用它创建下拉列表,请对您的代码进行修改。我相信这就是你所追求的:
Not sure entirely what you're asking for here (as it looks like you already have this working with checkboxes), but you can in fact post multiple values with a select box. You just use the
multiple
attribute, and specify the name as an array with the square brackets:If you post a form with this, selecting woman 2 & 3,
var_dump($_POST);
yields:Alternatively, if you want the values of your checkboxes to come through in a similar fashion, change them so they all have the same
name
, but with the square brackets on the end. This HTML would yield similar POST data:So, to create a dropdown using this, here's an adaptation of your code. I believe this is what you're after: