Home >Backend Development >PHP Tutorial >Summary of small knowledge points_PHP tutorial

Summary of small knowledge points_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 10:39:39840browse

checkbox usage

 <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]

Here strpos is to detect whether the string contains a certain string!

strpos returns an integer (returns logical false if not found)
'true' is converted to 0
in numeric comparisons If the first character of $row['flag'] is c, it happens to be matched
Other characters returned are not 0, so the match will not be successful.

When the parameter is passed as a string, how to convert it into an array and display the output.

 <?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;
				 }
			 }
			?>

Database insertion

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>";

}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/729845.htmlTechArticlecheckbox usage input id="flagc" type ="checkbox" value="c" name="flags[] "?php if(strpos($row['flag'],'c')!==false) echo "checked='checked'" ;?/Recommended [c] input id="flaga" type ="ch. ..
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