|
Posted by NC on 02/07/06 20:29
Jim S. wrote:
>
> if i have an array, $details how can i put it in a table database?
If you told us what the structure of the array was and how array
elements are mapped to database fields, it would be easier to advise
you on this... Here's a simple example:
$details = array(1 => 'One', 2 => 'Two', 3 => 'Three');
$flag = 0;
$query = 'INSERT INTO tbl_name (id, description) VALUES ';
foreach ($details as $id=>$description) {
if ($flag == 0) {
$query .= " ($id, '$description')";
$flag = 1;
} else {
$query .= ", ($id, '$description')";
}
}
mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
or die('Could not connect: ' . mysql_error());
mysql_select_db('my_database')
or die('Could not select database');
$result = mysql_query($query)
or die('Query failed: ' . mysql_error());
Cheers,
NC
Navigation:
[Reply to this message]
|