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
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)";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.