You are here: Re: array varaiable to a database field, how? « PHP SQL « IT news, forums, messages
Re: array varaiable to a database field, how?

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация