>>>>> "M" == "Mike"  <[EMAIL PROTECTED]> writes:

 > I am building an update string on the fly from form fields.I am
 > trying to add a comma between fields but I cant have one after the
 > last field.This is the code that doesnt work.Also I cant have a
 > comma at all in a table with only one updated field.

 > $keys = array_keys($HTTP_POST_VARS);
 > for($x = 2; $x < count($keys); $x++)
 > {
 > $updateString=$updateString.$keys[$x]."='".$HTTP_POST_VARS[$keys[$x]]."',";
 > }

 OK, making assumptions about the order of the fields in the form is dangerous.

 Making assumptions about the order of an associative array is doubly so, 
 although PHP seems remarkably forgiving about it.

 But assuming that's really what you want:

<?
 $pairs = array();

 foreach ( array_slice($HTTP_POST_VARS, 2) as $key => $value)
        $pairs[] = $key . "='" .  $value . "'";

 $updateString .= join(', ', $pairs);
?>


-- 
Robin Vickery.................................................
BlueCarrots, 14th Floor, 20 Eastbourne Terrace, London, W2 6LE

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to