upperbid Posted August 4, 2009 Share Posted August 4, 2009 In the code below, I receive a list of users waiting to be approved with check boxes for either deleting or approving. Everything works fine on the query for display and the deleting, but when I am trying to get the data for an INSERT statement, it is not working correctly. To make this easier to resolve, I have shown the relevant code and placed print "$del_id, $email, $fname, $lname"; in the area where I need that info. When I select the approve checkbox for designated users (say I might select 2 out of 20 displayed) and click submit, it shows the right amount of 2 columns with the correct user IDs, but the email, fname and lname are all the same for the users I've selected (showing the data from the last row in the initial displayed results of users). e.g. testtest3589, [email protected], ed smith testtest, [email protected], robert john (this is the last row in the displayed results) becomes testtest3589, [email protected], robert john testtest, [email protected], robert john My relevant part of the code is below: while($r=mysql_fetch_array($result)) { $user = $r["username"]; $email = $r["email"]; $fname = $r["firstname"]; $lname = $r["lastname"]; //display the row echo "<tr><td><input type=\"checkbox\" name=\"usera[]\" value=\"$user\" /><input type=\"checkbox\" name=\"usera[]\" value=\"$user\" /><B>$user</B>, <input type=\"hidden\" name=\"email[]\" value=$email>$email, <input type=\"hidden\" name=\"fname[]\" value=$fname>$fname <input type=\"hidden\" name=\"lname[]\" value=$lname>$lname</BR></td></tr>"; } $count=mysql_num_rows($result); $checka = $_POST['usera']; if (count($checka) > 0) { for ($i=0;$i<count($checka);$i++) { $del_id = $checka[$i]; print "$del_id, $email, $fname, $lname"; } } Any help would be appreciated. Thanks. Link to comment https://forums.phpfreaks.com/topic/168757-solved-printing-a-few-selected-results-from-multiple-checkboxes-in-a-larger-list/ Share on other sites More sharing options...
phpSensei Posted August 4, 2009 Share Posted August 4, 2009 print this out $user = $r["username"]; $email = $r["email"]; $fname = $r["firstname"]; $lname = $r["lastname"]; and see what it outputs. Link to comment https://forums.phpfreaks.com/topic/168757-solved-printing-a-few-selected-results-from-multiple-checkboxes-in-a-larger-list/#findComment-890356 Share on other sites More sharing options...
upperbid Posted August 4, 2009 Author Share Posted August 4, 2009 That part prints out fine, that's the first two lines in my e.g., but that is not what I need to print out the selected checkboxes. Link to comment https://forums.phpfreaks.com/topic/168757-solved-printing-a-few-selected-results-from-multiple-checkboxes-in-a-larger-list/#findComment-890360 Share on other sites More sharing options...
phpSensei Posted August 4, 2009 Share Posted August 4, 2009 That part prints out fine, that's the first two lines in my e.g., but that is not what I need to print out the selected checkboxes. When the script displays the checkbox lists, look at the values of the checkboxes and see what they are. check if they are what they are suposed to be. (i.e. fisrtname, lastname..etc) Link to comment https://forums.phpfreaks.com/topic/168757-solved-printing-a-few-selected-results-from-multiple-checkboxes-in-a-larger-list/#findComment-890366 Share on other sites More sharing options...
upperbid Posted August 4, 2009 Author Share Posted August 4, 2009 Yes, they come out exactly like they should be. As I already stated, the problem is in the print line I posted. There needs to be some other code that I'm missing. Link to comment https://forums.phpfreaks.com/topic/168757-solved-printing-a-few-selected-results-from-multiple-checkboxes-in-a-larger-list/#findComment-890370 Share on other sites More sharing options...
phpSensei Posted August 4, 2009 Share Posted August 4, 2009 $del_id = $checka[$i]; print "$del_id, $email, $fname, $lname"; that print is suposed to be inside the WHILE which gets the data from the database.. if you select 2 users, you will get 2nd one only, the variables inside the WHILE loop wont transition over inside another loop. Link to comment https://forums.phpfreaks.com/topic/168757-solved-printing-a-few-selected-results-from-multiple-checkboxes-in-a-larger-list/#findComment-890372 Share on other sites More sharing options...
phpSensei Posted August 4, 2009 Share Posted August 4, 2009 try if (count($checka) > 0) { for ($i=0;$i<count($checka);$i++) { $del_id = $checka[$i]; $sql = mysql_query("SELECT * FROM table_name WHERE user_id = '$del_id'") or die(mysql_error()); $row = mysql_fetch_array($sql); print $row['user_id']; print $row['firstname']; print $row['lastname']; print $row['email']; } } change this $sql = mysql_query("SELECT * FROM table_name WHERE user_id = '$del_id'") or die(mysql_error()); to whatever is your table name, and user id column name. Also change print $row['user_id']; print $row['firstname']; print $row['lastname']; print $row['email']; to the right column names... Link to comment https://forums.phpfreaks.com/topic/168757-solved-printing-a-few-selected-results-from-multiple-checkboxes-in-a-larger-list/#findComment-890375 Share on other sites More sharing options...
upperbid Posted August 4, 2009 Author Share Posted August 4, 2009 Thank you, your answers helped me resolve the problem. Where I had the print statements, I actually needed to be able to use that for an INSERT command and now it works. Link to comment https://forums.phpfreaks.com/topic/168757-solved-printing-a-few-selected-results-from-multiple-checkboxes-in-a-larger-list/#findComment-890394 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.