Re: [請益] 關於含0陣列的個數

看板PHP作者 (老公老王傻傻分不清楚! B)時間19年前 (2006/06/25 13:01), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串5/6 (看更多)
※ 引述《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
文章代碼(AID): #14dXZ2yF (PHP)
文章代碼(AID): #14dXZ2yF (PHP)