faqts : Computers : Programming : Languages : PHP : Database Backed Sites : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

38 of 52 people (73%) answered Yes
Recently 5 of 10 people (50%) answered Yes


Can i use array for INSERT query?

May 2nd, 2002 01:24
Techek, Max Gall,

Depends! I'll assume you're talking about say .. PHP and MySQL. In that 
case you could do this :
// your array
$ar = array("Techek","Logix","Marlow","Happy");
// produce a string with the contents of the array
$str = "'".implode("','",$ar)."'"; // 
returns "'Techek','Logix','Marlow','Happy'"
// make a sql-query to be fired at your DB
$sql = "INSERT INTO table SET names ($str)";
// connect and fire here!
$result = mysql_query($sql);
It might need to be modified, but this is the main idea. Build on it - 
or ask a more specific way ... =8-)