Home > Backend Development > PHP Tutorial > 根据条件循环复框,麻烦各位朋友帮小弟我看一下应该怎样改

根据条件循环复框,麻烦各位朋友帮小弟我看一下应该怎样改

WBOY
Release: 2016-06-13 12:47:17
Original
932 people have browsed it

根据条件循环复框,麻烦各位朋友帮我看一下应该怎样改

<br />
 <?php<br />
 $sql = "SELECT `id` , `name`<br />
FROM `interior_authority`";<br />
$row['authorityid']= "a,b,c,d,e";//这个是值是为了方便查看加上去,原本这个值是从数据库里读取出来的。<br />
$authority = explode(",",$row['authorityid']);<br />
//$row数组$row[id]值分别为"a,b,c,d,e,f,c",这值也是为了方便查看加上去的,原值是从数据库读取出来的。<br />
$sql = mysql_query($sql,$conn);<br />
 while($row = mysql_fetch_array($sql)){<br />
	 foreach($authority as $value){<br />
		 if($row['id']==$value){<br />
			echo<<<EOD<br />
<label><input name="chk_authority[$row[id]]"  type="checkbox" id="chk_authority" value="$row[id]" checked="checked"/> $row[name]</label><br />
EOD;<br />
		 }<br />
	}<br />
}<br />
 ?><br />
Copy after login

我想要的结果是$row['id']==$value 复选框就打上"√",其它不相等的就直接显示出来!
现在的问题是复选框能上"√",但那些没打上"√"的不会显出来,如果在whiel循环里多加一条
<br />
echo<<<EOD<br />
<label><input name="chk_authority[$row[id]]"  type="checkbox" id="chk_authority" value="$row[id]" checked="checked"/> $row[name]</label><br />
EOD;<br />
Copy after login

那他就会重复显示;
希望能各位朋友帮个忙
PHP根据条件循环显示

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