Jump to content

array, foreach and UPDATE


Siggles

Recommended Posts

I have a form that is sending the following POST array to another page ..

 

Key: markedinv10; Value: 10
Key: markedinv11; Value: 11
Key: markedinv19; Value: 19
Key: markedinv20; Value: 20
Key: x; Value: 6
Key: y; Value: 8
Key: opt; Value: updateinv

 

I want to run a loop of UPDATE statements to a MySQL database updating the rows a field matches the value of every key in the array starting with markedinv...

 

(the x and y are for the submit image and the opt key is for a switch statement).

 

So for example:

 

foreach ($_POST as $key => $val){
while ($key == markediv^){
$query = mysql_query("UPDATE timesheet SET marked_invoiced='1' WHERE log_id = '$val' ");
}

 

Can I loop an update statement first of all and if so what php can I use to check for markedinv^ and get the $val from them?

 

many thanks for your help

Link to comment
Share on other sites

I changed the form to this

 

<input name=\"markedinv[]\"

 

then the processing page to this

 

foreach ($_POST['markedinv'] as $key => $val){

 

echo "Key: $key; Value: $val<br />\n";

$query = mysql_query("UPDATE timesheet SET marked_invoiced='1' WHERE log_id = '$val' ");

 

}

 

which works to tick the boxes. Yay! Now I need to work out how to untick the boxes (or make the value of marked_invoice to 0 instead of to 1)!!

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.