Home > php教程 > php手册 > body text

小知识点总结

WBOY
Release: 2016-06-13 09:43:53
Original
759 people have browsed it

checkbox 用法

 <input id="flagc" type ="checkbox" value="c" name="flags[]"<?php if(strpos($row['flag'],'c')!==false) echo "checked='checked'" ;?>/>推荐[c]
			    <input id="flaga" type ="checkbox" value="a" name="flags[]"<?php if(strpos($row['flag'],'a')!==false) echo "checked='checked'" ;?>/>特荐[a]
			    <input id="flagh" type ="checkbox" value="h" name="flags[]"<?php if(strpos($row['flag'],'h')!==false) echo "checked='checked'" ;?>/>头条[h]
			    <input id="flago" type ="checkbox" value="o" name="flags[]"<?php if(strpos($row['flag'],'o')!==false) echo "checked='checked'" ;?>/>热门[o]
			    <input id="flagn" type ="checkbox" value="n" name="flags[]"<?php if(strpos($row['flag'],'n')!==false) echo "checked='checked'" ;?>/>最新[n]
Copy after login

这里strpos是检测字符串中是否包含某个字符串!

strpos 返回整数(找不到返回逻辑假)
'true' 在数值比较中被转换为 0
如果 $row['flag'] 第一个字符为 c 时,恰巧被匹配
其他字符返回的都不是 0,所以不会匹配成功。

当参数传递为字符串是如何转变成数组与显示输出。

 <?php
			 $flags = explode(',',$v['flag']) ;
			 foreach($flags as $x){
			     switch($x){
				     case c:
					 echo "推荐[c]";
					 break;
					 case a:
					 echo "特荐[a]";
					 break;
					 case h:
					 echo "头条[h]";
					 break;
					 case o:
					 echo "热门[o]";
					 break;
					 case n:
					 echo "最新[n]";
					 break;
				 }
			 }
			?>
Copy after login

数据库插入

else if($_GET['do']=='editok'){
	$id = $_POST['id'];
	$checked = $_POST['checked'];
	$flag = $_POST['flags'];
	$flags=implode(",",$flag);
	$sql = 'update djs_skstudent_voice set checked='.$checked.',flag="'.$flags.'" where id='.$id;
	$dsql->ExecuteNoneQuery($sql);
	echo "<script> window.location.href='student_voice.php';</script>";

}
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template