Re: [請益] 關於含0陣列的個數
※ 引述《submarine (submarine)》之銘言:
: 我是想寫寄信system 依照不同的條件 會從資料庫裡把名字選出來
: 在每個名字之前會有一個checkbox 是依照陣列的方式命名的
: ex
: 老王<input type="checkbox" name="p[0]" value="checkbox" />
: 小明<input type="checkbox" name="p[1]" value="checkbox" />
: …
: 在第一個網頁選完之後,在處理的網頁,我就碰到上面的問題了
: 之後 我就要知道是哪些index被選上
: 第一個想到的是用迴圈 但是我用
: $che=$_POST["p"];
: $num=sizeof($che);
: for ($qq=0;$qq<$num;$qq++)
: {
: if($che[$qq]==1) echo($nam[$qq].$mai[$qq]);
: }
如果是資料庫的話
table: test
id, name, mail
==========
1, 老王, aaa@xxx.xxx
2, 小明, bbb@xxx.xxx
3, 阿明, ccc@xxx.xxx
......
ex
老王<input type="checkbox" name="p[0]" value="0" /> (假如我勾了)
小明<input type="checkbox" name="p[1]" value="1" />
阿明<input type="checkbox" name="p[2]" value="2" /> (假如我勾了)
.....
POST 只會傳有勾選的值。
$sql = 'select * from test';
......
while($tmp = mysql_fetch_array($result))
$arr[$tmp['id']] = $tmp;
$che = $_POST['p'];
foreach($che as $id)
echo $arr[$id]['name'].$arr[$id]['mail'];
你試試吧!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.161.54.250
推
06/25 23:15, , 1F
06/25 23:15, 1F
討論串 (同標題文章)
PHP 近期熱門文章
PTT數位生活區 即時熱門文章