md7dani Posted November 25, 2009 Share Posted November 25, 2009 I've got a list with checkboxes and rows from a table like this: checkbox 1, userid, sendid, date, subject, mess checkbox 2, userid, sendid, date, subject, mess . . So I have this code: $i=0; if(isset($_POST['submit'])) { // if page is submitted echo the form $result2 = mysql_query("SELECT * FROM Mail"); while($row2 = mysql_fetch_array($result2)){ if ($_POST['email'][$i]!="") { echo $row2['userID']; echo $row2['sendID']; echo $row2['subject']; echo $row2['senddate']; } $i=$i+1; } } // End if (!isset($_POST['Submit'])) the code should echo the row where the checkbox is checked. The code works if you check many in a row, but when you check only one for ex checkbox5 with index 4, it allways echoes index 0. Can you see where the problem is?? Link to comment https://forums.phpfreaks.com/topic/182900-get-checkbox-value/ Share on other sites More sharing options...
defeated Posted November 25, 2009 Share Posted November 25, 2009 Not sure I entirely follow. but... $1=0; You set the index to zero. Link to comment https://forums.phpfreaks.com/topic/182900-get-checkbox-value/#findComment-965401 Share on other sites More sharing options...
md7dani Posted November 25, 2009 Author Share Posted November 25, 2009 Not sure I entirely follow. but... $1=0; You set the index to zero. $i=0; is set to start from the first checkbox. It's outside isset so if you press subit $ is not affected. What the code does: when submit is pressed: 1 it enters the if(isset($_POST['submit'])) 2 get rows from table 3 as long as there are rows in table 4 if checkbox is checked (starting from 0), echo the row 5 increase $i with 1 say we have in list: ckbox 1, Jake,Sam,work,091130 ckbox 2, Greg,Bobby,day off,091204 ckbox 3, Mr X,Gordon,vacation,091004 I check checkbox 3 in the list: first: checkbox 1 is not checked,$i=0, don't echo row, $i=1 second: checkbox 2 is not checked,$i=1, don't echo row, $i=2 third: checkbox 3 is checked,$i=2, echo rows, $i=3 Link to comment https://forums.phpfreaks.com/topic/182900-get-checkbox-value/#findComment-965570 Share on other sites More sharing options...
md7dani Posted November 25, 2009 Author Share Posted November 25, 2009 The problem is when I create the checkboxes: $s=0; <?php while($row = mysql_fetch_array($result)){ ?> <input type="checkbox" value="Electricity" name="email[" . <? echo $s; ?> . "]"> <?php $s = $s + 1; } ?> Do you see any wrong with the code above?? what I need is to create the checkboxes like this: email[0] email[1] email[2] . . Link to comment https://forums.phpfreaks.com/topic/182900-get-checkbox-value/#findComment-965625 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.