checkboxs

Mr Boggy Man

New member
checkboxs

טוב הכנתי form כזה:
echo " <center> <form action=update.php method=POST> <table border=0 bgcolor=#C2CDDB width=100%> <tr bgcolor=#ECF0F4 align=center> <th>U</th><th width=20>id</th><th width=50>Url</th><th>Name</th><th>Description</th> </tr>"; while ($i < $num) { $id = mysql_result($r,$i,id) or die ("No current link posted"); $name = mysql_result($r,$i,name); $url = mysql_result($r,$i,url); $des = mysql_result($r,$i,des); echo " <tr bgcolor=#ECF0F4 align=center> <td><input type=checkbox name='id[]' value='$id'></td><td>$id</td><td><input type=text maxlength=100 value=$url size=50></td><td width=157><input type=text value=$name></a></td><td><input type=text value=$des size=63></td> </tr>"; $i++; } echo " </table><BR><input type=hidden name=user value=$r1><input type=hidden name=pass value=$r2><input type=hidden name=delink value=yes><input type=hidden name=num value=$num> <input type=submit Value=send><input type=reset value=Reset> </form></center>";​
עכשיו הקטע הוא שאני לא יודע מה לעשות עם הcheckboxs איך אני עושה שהם ימחקו מהטבלת מייאסקיואל שלי? כלומר איך עובדים עם checkbox ואיך אני יודע מה סומן ומה לא?
 

behemot

New member
בבדיקה של הFROM תבדוק אם הערך

של המשתנה של הCHECKBOX הוא ON
 

orenphp

New member
תשובה טיפה מאוחרת

אבל אני מקווה שלא מאוחרת מדי. ככה אתה עובר על המשתנה שהוא מערך של id שנבחרו(!) (במידה והוא בכלל קיים - כלומר מישהו בחר איזה checkbox):
//make sure that nobody will send you a mixed up $id variable. if (isset($id) && is_array($id) && count($id)>0) { //remember, only the selected IDZ will be in the array. $q = "select * from table_name where "; for($i=0, $cond="";$i<count($id);$i++) { //delete, update or whatever you want to do with the $value variable.... //in this example, build the query: $q .= $cond."ID=".$id[$i]; $cond = " OR "; //or: $q = ($i) ? " OR ID=".$id[$i] : " ID=".$id[$i]"; } mysql_query($q); echo "the rows with the checked IDZ were deleted"; } else { echo "no checkbox option was checked, or somebody is trying to mess with our code"; }​
הקוד לא נבדק אבל אמור לעבוד.
 
למעלה