$query = "UPDATE tablename SET "; foreach($_POST AS $key => $value) $query .= "$key = '$value',"; $query[strlen($query)-1] = ""; $query .= " WHERE id = '$_GET[id]'; Or something? On Tue, 2002-11-12 at 13:58, David Rice wrote: > > > 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) ; > etc... > > > > _________________________________________________________________ > Help STOP SPAM with the new MSN 8 and get 2 months FREE* > http://join.msn.com/?page=features/junkmail > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- Adam Voigt (adam@cryptocomm.com) The Cryptocomm Group My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc
Attachment:
signature.asc
Description: This is a digitally signed message part