scarhand Posted October 22, 2007 Share Posted October 22, 2007 OK I have this somewhat figured out after about an hour of googling. So what I have right now is this: <form method="post"> <?php $showshoutsql = mysql_query("SELECT * FROM shouts ORDER BY $sortshout $ordershout"); $showshoutcount = mysql_num_rows($showshoutsql); if (isset($_POST['removeselected'])) { for ($i = 0; $i < $showshoutcount; $i++) { $chex = $_POST['chex'][$i]; echo "$chex <br />"; } } while ($row = mysql_fetch_array($showshoutsql)) { echo "<input type=\"checkbox\" value=\"$id\" name=\"chex[]\"> \n"; } ?> <br /> <input name="removeselected" type="submit" value="Remove Selected"> </form> Now I know that THIS works. However, I do not want the checkbox's names to be "chex[]", I only want them to be "chex", otherwise they won't work with my Javascript code. The problem is that when I remove the "[]", when $chex is echo'd it does not show the VALUE of each checkbox. Any help would be greatly appreciated as I've tried multiple different things and none seem to work. Quote Link to comment https://forums.phpfreaks.com/topic/74300-solved-multiple-mysql-row-deletion-via-checkboxes/ Share on other sites More sharing options...
MadTechie Posted October 22, 2007 Share Posted October 22, 2007 IMO i think this is javascript problem.. (if you can use an array in your javascript) not a PHP one, sure we can suggest "workarounds" but why not just fix the fault ! Quote Link to comment https://forums.phpfreaks.com/topic/74300-solved-multiple-mysql-row-deletion-via-checkboxes/#findComment-375371 Share on other sites More sharing options...
scarhand Posted October 22, 2007 Author Share Posted October 22, 2007 IMO i think this is javascript problem.. (if you can use an array in your javascript) not a PHP one, sure we can suggest "workarounds" but why not just fix the fault ! im sure its a simple way of turning the name "chex" into an array before it is echo'd i mean if i go ahead and just make chex an array once its pulled from the database then that means i have to re-write all the javascript code Quote Link to comment https://forums.phpfreaks.com/topic/74300-solved-multiple-mysql-row-deletion-via-checkboxes/#findComment-375374 Share on other sites More sharing options...
GingerRobot Posted October 22, 2007 Share Posted October 22, 2007 I agree. Modify the javascript to work with the array. It is the best way of passing all of the values of the IDs. If its really not an option, you'd have to employ some more javascript to do something like populate a hidden field with a list of IDs, separated by commas, which you could then separate out in php. Better method is to modify the javascript though. Quote Link to comment https://forums.phpfreaks.com/topic/74300-solved-multiple-mysql-row-deletion-via-checkboxes/#findComment-375375 Share on other sites More sharing options...
GingerRobot Posted October 22, 2007 Share Posted October 22, 2007 IMO i think this is javascript problem.. (if you can use an array in your javascript) not a PHP one, sure we can suggest "workarounds" but why not just fix the fault ! im sure its a simple way of turning the name "chex" into an array before it is echo'd i mean if i go ahead and just make chex an array once its pulled from the database then that means i have to re-write all the javascript code You miss the point. Unless chex is an array, then you will only ever recieve the last value from your $_POST array. A string can only hold one value - you need to pass lots of related values, for which an array is best. Quote Link to comment https://forums.phpfreaks.com/topic/74300-solved-multiple-mysql-row-deletion-via-checkboxes/#findComment-375376 Share on other sites More sharing options...
scarhand Posted October 22, 2007 Author Share Posted October 22, 2007 IMO i think this is javascript problem.. (if you can use an array in your javascript) not a PHP one, sure we can suggest "workarounds" but why not just fix the fault ! im sure its a simple way of turning the name "chex" into an array before it is echo'd i mean if i go ahead and just make chex an array once its pulled from the database then that means i have to re-write all the javascript code You miss the point. Unless chex is an array, then you will only ever recieve the last value from your $_POST array. A string can only hold one value - you need to pass lots of related values, for which an array is best. that makes sense as to why using foreach was getting me nowhere. i am rewriting the javascript. thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/74300-solved-multiple-mysql-row-deletion-via-checkboxes/#findComment-375380 Share on other sites More sharing options...
MadTechie Posted October 22, 2007 Share Posted October 22, 2007 as an idea.. why not <form method="post"> <?php $showshoutsql = mysql_query("SELECT * FROM shouts ORDER BY $sortshout $ordershout"); $showshoutcount = mysql_num_rows($showshoutsql); if (isset($_POST['removeselected'])) { for ($i = 0; $i < $showshoutcount; $i++) { $chex = $_POST['chex$i']; echo "$chex <br />"; } } $n=0; while ($row = mysql_fetch_array($showshoutsql)) { echo "<input type=\"checkbox\" value=\"$id\" name=\"chex$n\"> \n"; $n++; } ?> <br /> <input name="removeselected" type="submit" value="Remove Selected"> </form> EDIT: WooHoo re-writing the JS is much better, Quote Link to comment https://forums.phpfreaks.com/topic/74300-solved-multiple-mysql-row-deletion-via-checkboxes/#findComment-375381 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.