比对MySQL和array相同值有关问题

WBOY
Release: 2016-06-13 12:10:48
Original
908 people have browsed it

比对MySQL和array相同值问题

<br /><select size=5 name=\"class[]\" ><br /><?php<br />//link里面固定的值是1,2,3<br /> //$class的值可能是{1,3}或{2},看使用者选的都不一定<br />$i=0;<br />$query = $db->query(\"SELECT * FROM `link` );<br />foreach($query->result() as $row){<br />$link_id=$row->link_id;<br />?><br /><option value=\"<?php echo $link_id ;?>\" <?php if($class[$i]==$link_id){ echo \"selected='selected'\";} ?>>< ?php echo $row->link_name;?><br /><?php<br />$i++;<br />}<br />?><br /></select><br />
Copy after login

这样印出会有问题
假设$class的值是2
程式去比对一定不成功
请问要怎么改?
------解决思路----------------------
<br /><br />//如果你的$class是一个数组,可以用in_array();函数<br />in_array($link_id,$class)<br /><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