for loop of UPDATE, how?
Posted: Tue Aug 01, 2006 11:59 pm
What is the syntax for breaking apart UPDATE queries within a PHP for loop?
Here's my for loop that concatenates the string
Here's the resulting query:
How do I use the for loop to break the strings up and send them seperately? Do I call the mysql_query($my_sql_string2, $con) from within the for loop?
Thanks in advance
Here's my for loop that concatenates the string
Code: Select all
for ($j=1; $j<=$i-1; $j++)
{
$my_sql_string2 .= "UPDATE guest_login SET";
$my_sql_string2 .= " FIRST_NAME= '{$_REQUEST['first_name'.$j]}', LAST_NAME= '{$_REQUEST['last_name'.$j]}', EMAIL_ADDRESS= '{$_REQUEST['email_address'.$j]}', WHAT_U_LIKED= '{$_REQUEST['what_u_liked'.$j]}'";
$my_sql_string2 .= " WHERE ";
$my_sql_string2 .= "VISITOR_ID='{$_REQUEST['hidden_visitor_id'.$j]}'";
$my_sql_string2 .= " ";
}Code: Select all
UPDATE guest_login SET FIRST_NAME= 'bob2', LAST_NAME= 'newhart', EMAIL_ADDRESS= 'bob@newhart.com', WHAT_U_LIKED= 'yes' WHERE VISITOR_ID='31' UPDATE guest_login SET FIRST_NAME= 'bob3', LAST_NAME= 'newhart', EMAIL_ADDRESS= 'bob2@newhart.com', WHAT_U_LIKED= 'yes2' WHERE VISITOR_ID='32' UPDATE guest_login SET FIRST_NAME= 'bob4', LAST_NAME= 'newhart', EMAIL_ADDRESS= 'bob3@newhart.com', WHAT_U_LIKED= 'yes' WHERE VISITOR_ID='33'Thanks in advance