Re: array output as a variable?
| From: | Brian Clark | Date: | Thu, 12 Apr 2001 07:10:46 +0000 |
| Subject: | Re: array output as a variable? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-48254@lists.php.net to get a copy of this message | ||
@ 2:39:12 AM on 4/12/01, Brian Clark wrote:
...
> @ 2:13:10 AM on 4/12/01, midget2000x wrote:
...
>> //declare the array
>> $info_request = array (1 =>
>> "firstname","lastname","email","howfound","optin","comments","request_type","request_bucket","date");
^^^^
Sorry, I guess this would be more complete:
<?php
$tablename = 'foo';
$info = array(0 => array('billy
bob','joe','email','yahoo','sort
of','foo','firm','large','date'),
1 => array('james
j','frank','email','google','no','bar','soft','small','date'));
while(list(,$array) = each($info))
{
$results = 'INSERT INTO $tablename VALUES(';
while(list($idx,$value) = each($array))
{
$results .= ($idx == (sizeof($array) - 1) ? "'$value'" :
"'$value',");
}
$results .= ')';
print "$results\n"; /* INSERT here. */
}
?>
I guess it could be made into a function($info,$table) -- whatever,
but you'd need error checking a returns on the inserts.
-Brian
--
PGP is spoken here: 0xE4D0C7C8
Please do not carbon copy me on list replies.