作者ast9869 (老公老王傻傻分不清楚! B)
看板PHP
标题Re: [请益] 关於含0阵列的个数
时间Sun Jun 25 13:16:18 2006
※ 引述《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, 老王,
[email protected]
2, 小明,
[email protected]
3, 阿明,
[email protected]
......
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
1F:推 submarine:嗯 谢谢大大 06/25 23:15