MySql Update.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux