Making an update query that adapts to the number of fields that are to be updated

Is there anyway to do like a for loop to create the values part of the query then combine it with the first part of the string.

something like what i have below... although something that works correctly as this doesn't.

$table is the table name
$num_headers is the number of headers (fieldnames) for that table
$table_headers is an array with the names of the headers
$values is an array with the names of the input boxes on the previous page

$query1 = "UPDATE ".$table." SET " ;

$query2 = ( for ($x=0; $x <=$num_headers; $x++){
". $table_headers[$x] . "=" . $values[$x] . " , "
}) ;

$query = $query1.$query2 ;

$result = mysql_query ($query) ;

Help STOP SPAM with the new MSN 8 and get 2 months FREE*

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to