自学的小疑点,帮忙看看

WBOY
Release: 2016-06-13 12:16:54
Original
859 people have browsed it

自学的小问题,帮忙看看
为什么有数据 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 />
Copy after login

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

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

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