tsm1248 Posted December 12, 2010 Share Posted December 12, 2010 Ok so i want to grab an id from the checkbox then grab the option drop down associated with that check box and update a mysql row here is my code so far any help is awesome help taaaanks guys <?php mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("db1") or die(mysql_error()); $query = "SELECT * FROM tickets ORDER BY id DESC"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { print "<input name='delete[]' value='{$row['id']}' type='checkbox'>"; mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("db1") or die(mysql_error()); $query2 = "SELECT * FROM admin"; $result2 = mysql_query($query2) or die(mysql_error()); print "<form name='namestoupdate' method='post' action='update.php'>\n"; print '<select>'; while($row2 = mysql_fetch_array($result2)) { if ($row2['priv']==prov){print '<option value="'.$row2['user'].'" name="prov['.$i++.']">'.$row2['user'].'</option>';} } print '</select>'; print "<input type='submit' value='submit' />"; print "</form>"; } ?> Visual aid Quote Link to comment https://forums.phpfreaks.com/topic/221439-grab-data-from-multiple-checkboxes-and-multiple-dropdowns/ Share on other sites More sharing options...
laffin Posted December 13, 2010 Share Posted December 13, 2010 You don't tie in your checkbox with its dropdown list if ($row2['priv']==prov){print '<option value="'.$row2['user'].'" name="prov['.$i++.']">'.$row2['user'].'</option>';} } change to: if ($row2['priv']==prov){print '<option value="'.$row2['user'].'" name="prov['.$row['id'].']">'.$row2['user'].'</option>';} } checkbox returns a value only when checked listbox returns 1 item which is selected so the key for the listbox can be the value from the checkbox, so know you know which checkbox belongs to which list item this creates a mult-dimensional array in your code check yer checkboxes $delete[]=array(); if(isset($_POST['delete'])) { foreach($_POST['delete'] as $ticket) $delete[]=$_POST['prov'][$ticket]; } echo count($delete) . " tickets to remove <br />"; for($i=0;$i<count($delete);$i++) { $n=$i+1; echo " #{$n} - {$delete[$i]} <br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/221439-grab-data-from-multiple-checkboxes-and-multiple-dropdowns/#findComment-1146470 Share on other sites More sharing options...
tsm1248 Posted December 13, 2010 Author Share Posted December 13, 2010 First off thanks for responding i really need some help on this one a bit stuck test1.php <?php mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("db1") or die(mysql_error()); $query = "SELECT * FROM tickets ORDER BY id DESC"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { print "<input name='delete[]' value='{$row['id']}' type='checkbox'>"; mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("db1") or die(mysql_error()); $query2 = "SELECT * FROM admin"; $result2 = mysql_query($query2) or die(mysql_error()); print "<form name='namestoupdate' method='post' action='test.php'>\n"; print '<select>'; while($row2 = mysql_fetch_array($result2)) { if ($row2['priv']==prov){print '<option value="'.$row2['user'].'" name="prov['.$row['id'].']">'.$row2['user'].'</option>';} } print '</select>'; print "<input type='submit' value='submit' />"; print "</form>"; } ?> test.php <?php $delete[]=array(); if(isset($_POST['delete'])){ foreach($_POST['delete'] as $ticket) $delete[]=$_POST['prov'][$ticket]; } echo count($delete) . " tickets to remove <br />"; for($i=0;$i<count($delete);$i++){ $n=$i+1; echo " #{$n} - {$delete[$i]} <br />"; } ?> This is what the code now looks like and outputs the following regardless if a checkbox is checked and its the same output each time output 1 tickets to remove #1 - Array Quote Link to comment https://forums.phpfreaks.com/topic/221439-grab-data-from-multiple-checkboxes-and-multiple-dropdowns/#findComment-1146624 Share on other sites More sharing options...
tsm1248 Posted December 13, 2010 Author Share Posted December 13, 2010 I need to tie the check boxes with them so i can update the correct unique field from the checkboxes id and then insert one of the options into the row Quote Link to comment https://forums.phpfreaks.com/topic/221439-grab-data-from-multiple-checkboxes-and-multiple-dropdowns/#findComment-1146632 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.