欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php checkbox 取值詳細(xì)說明

 更新時(shí)間:2010年08月19日 21:45:23   作者:  
php的checkbox取值方式跟其它語(yǔ)言有點(diǎn)不同,主要是因?yàn)閜hp中數(shù)組的合理使用。
設(shè)我們有一個(gè)html頁(yè)面,代碼如下:
復(fù)制代碼 代碼如下:

<FORM method="post" action="checkTest.php">
<INPUT name="test[]" type="checkbox" value="1" />
<INPUT type="checkbox" name="test[]" value="2" />
<INPUT type="checkbox" name="test[]" value="3" />
<INPUT type="checkbox" name="test[]" value="4" />
<INPUT type="checkbox" name="test[]" value="5" />
<INPUT type="submit" name="Submit" value="Submit" />
</FORM>

注意上面input的name屬性,各個(gè)屬性內(nèi)容都一樣,而且都是test[],加上[]的原因在于讓test的內(nèi)容變成數(shù)組形式傳遞。
checkTest.php的代碼內(nèi)容如下:
復(fù)制代碼 代碼如下:

<?php
echo implode(",",$_POST['test']);
?>

我們輸出內(nèi)容時(shí)只需要注意利用implode函數(shù)將數(shù)組內(nèi)容轉(zhuǎn)化為字符串即可。
注:該功能可在刪除多記錄等場(chǎng)合運(yùn)用。如Delete from tbl where ID in (implode(",",$_POST['test']))即可。
實(shí)例代碼:
復(fù)制代碼 代碼如下:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標(biāo)題文檔</title>
</head>
<body>
html復(fù)選框如果要以數(shù)據(jù)組形式發(fā)送給php腳本處理就必須以如checkbox[]這形式
<form id="form1" name="form1" method="post" action="">
<label>
<input type="checkbox" name="checkbox[]" value="1" />
</label>
<label>
<input type="checkbox" name="checkbox[]" value="2" />
</label>
<label>
<input type="checkbox" name="checkbox[]" value="www.dbjr.com.cn" />
</label>
<label>
<input type="checkbox" name="checkbox[]" value="jb51.net" />
</label>
<label>
<input type="submit" name="Submit" value="提交" />
</label>
</form>
</body>
</html>
<?
//判斷是否點(diǎn)擊提交
if( $_POST )
{
$array = $_POST['checkbox'];
print_r($array);
}
/*
結(jié)果:
Array
(
[0] => 1
[1] => 2
[2] => www.dbjr.com.cn
[3] => jb51.net
)
簡(jiǎn)單的很多事情在做之前覺得復(fù)雜但做起來就很容易了,像這個(gè)復(fù)選框代碼就是這樣了。
*/
?>

相關(guān)文章

最新評(píng)論