Re: Tough one?
| From: | Robin Vickery | Date: | Wed, 21 Feb 2001 21:12:50 +0000 |
| Subject: | Re: Tough one? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-41055@lists.php.net to get a copy of this message | ||
>>>>> "M" == "Mike" <mpeloso@princeton.edu> 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