Home >Backend Development >PHP Tutorial >自学的小疑点,帮忙看看

自学的小疑点,帮忙看看

WBOY
WBOYOriginal
2016-06-13 12:16:54878browse

自学的小问题,帮忙看看
为什么有数据 checkbox 无法选中呢?哪里的问题 高手帮忙看看






<?php<br /><br />mysql_connect('localhost','root','root');<br />mysql_select_db('ceshi');<br />mysql_query('set names utf8');<br /><br />$sql="select * from test where username='小丁'";<br />$result=mysql_query($sql);<br />$row=mysql_fetch_assoc($result);<br /><br /><br />$a=$row['love'];<br />$arr=explode('|', $a);<br /><br />$ah=array('打麻将','看电影','英雄联盟','睡觉');<br /><br />?><br /><br />用户名:<input type="text" name="username" value="<?php echo $row['username'] ?>"/><br><br /><br />爱好:<?php  <br />        for ($i=0;$i<count($ah);$i++):<br />            $sled='';<br />            if(in_array($ah[i],$arr)){<br />                    $sled='checked';<br />            }<br /><br />    ?><br /><br />    <input type="checkbox" <?php echo $sled ?>><?php echo $ah[$i] ?><br /><br />    <?php<br />    endfor;<br />    ?><br />

------解决思路----------------------
if(in_array($ah[i],$arr)){

if(in_array($ah[$i],$arr)){
------解决思路----------------------
原来是这个问题!
if(in_array($ah[i],$arr)){
少了 $
应为
if(in_array($ah[$i],$arr)){

Statement:
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