Try this:

while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{   
$insert_fmt = "INSERT INTO %s VALUES('%s')"; //string format
$values = join("','", $data); //join the pieces of the array without regard for array size
$table_name = "tbl";

$import = sprintf($insert_fmt, $table_name, mysql_escape_string($values));
mysql_query($import) or die(mysql_error());

 }

Reference: http://www.php.net/manual/en/function.join.php - String function for joining the pieces of an array.

It goes without saying that you need to do the necessary validations to ensure that your queries don't trip up.

HTH


On Mon, Sep 28, 2009 at 8:57 AM, thea maina <theamaina@gmail.com> wrote:
Hi Ashford.
Thanks Man.
That might work..
I do create the table dynamically with varying columns and the first column is always a PK with a value..
i hope to dynamically populate it with some sample data.
I'll paste what works.
Any more help is appreciated..

regards

On Thu, Sep 24, 2009 at 5:27 PM, Ashford Kuria <kuriashford@gmail.com> wrote:
Unless your table "$table" is dynamic, you will encounter errors with all insets where column count is not valid

assume $table  is table_column-count
then

...
..
.
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$c = count($data); // get count of columns
$table = "table_$c"; // concat table name
$sqldata = ""; // empty sting for concatenation below

foreach($data as $dat)
$sqldata .= ', "'.msql_real_escape_string($dat).'"'; // convert $data into csv of quoted escaped values

$sqldata = substr($sqldata,2); // remove first space and comma ", "

if($c  > 0 and $c <= 22)
mysql_query("insert into $table values ($sqldata)", $connection);

if($c ==12)
echo "YIPEEEEE";

if($c > 22 or $c == 0)
echo "Call your  DBA - Mark";
}

Ashford K.






--
---------------------------------------------------------------------
Thea Maina
Nairobi Kenya
http://www.mafans.com
skype: thea.mnairobi

_______________________________________________
Skunkworks mailing list
Skunkworks@lists.my.co.ke
http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks
Other services @ http://my.co.ke
Other lists
-------------
Announce: http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks-announce
Science:  http://lists.my.co.ke/cgi-bin/mailman/listinfo/science
kazi:     http://lists.my.co.ke/cgi-bin/mailman/admin/kazi/general



--
blog: http://imma.wordpress.com