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
https://forums.phpfreaks.com/topic/145763-array-foreach-and-update/
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)!!

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.