Jump to content

Don't Even know how to ask it.


billgod

Recommended Posts

I hope this has never been answered before but I don't even know what to look for..  here is what I am doing.

 

database is doing a select to grab all names in db and putting checkbox next to them.  checkbox value is the id - unique key

 

echo "<tr><td><input type='checkbox' name='$rows[id]' value='$rows[id]'></td> <td> $rows[col_name]</td></tr>";

 

when I submit the form..  I need to find all that have check boxes and update the database.  How can I do this without having to do

 

if ($_POST[2]==2)

 

or some crazy thing like that.  anyone out there know an EASY way to do this?  yes I suck as a coder but this is for personal stuff not for a enterprise type site.

Link to comment
https://forums.phpfreaks.com/topic/264979-dont-even-know-how-to-ask-it/
Share on other sites

And to build upon the array example, it is a simple operation to create a query to update all the records in mass. Just use IN within the query's WHERE clause and implode the IDs. Of course you should run the array through a process to force them to be ints to prevent SQL injection.

//Force array values to integers and remove 0 values
$submittedIDs = array_filter(array_map('intval', $_POST['check']));

//Convert to comma separated string
$IDlistStr = implode(', ', $submittedIDs);

//Create UPDATE array
$query = "UPDATE table_name SET fieldname = 'somevalue" WHERE id IN ($IDlistStr)";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.