PHP 多选复选框checkbox怎么判断选中

WBOY
Release: 2016-06-13 12:22:11
Original
1521 people have browsed it

请教高手PHP 多选复选框checkbox如何判断选中?
数据库字段content有如果下数据:
s1,s2,s3,s4,s5
数据随时会变动,如果只有:s1,s2,s5,但是s1和s2是固定存在的


HTML:



......



PHP:
$sql="select * from `user_role` ";
$row_role = $db->getRow($sql);
$row_role = $row_role['content'];
$role=explode(',',$row_role);//分割成数组


如何才能做到如果数据库有:s1,s2,s3,则s3是选中状态


------解决思路----------------------

<br /><?php<br />/*$sql="select * from `user_role` ";<br />$row_role = $db->getRow($sql);<br />$row_role = $row_role['content'];<br />$role=explode(',',$row_role);//分割成数组*/<br />$role = array('s1','s2','s3');<br />?><br /><input type="checkbox" name="content[]" <?php if(in_array('s1',$role) && in_array('s2',$role) && in_array('s3',$role)){ ?>checked="checked"<?php } ?>  value="s3" ><br /><input type="checkbox" name="content[]"  value="s4" ><br /><input type="checkbox" name="content[]"  value="s5" ><br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template