Page 3 of 3

Re: Help - csv and mysql database compare ?

Posted: Fri Jul 31, 2009 10:04 am
by bidntrade
i see it ...

but im not sure how to get the IDs into the array....

since

Code: Select all

# // loop content of csv file, using comma as delemiter
# while (($data = fgetcsv($handle)) !== FALSE) {
if i put anything in this loop

$id only has one id at a time as it goes through ....

please remember ... im not that skillfull

Re: Help - csv and mysql database compare ?

Posted: Fri Jul 31, 2009 10:08 am
by VladSun
bidntrade wrote:please remember ... im not that skillfull
Yes, I remember - that's what we are trying to "fix" ;)

OK, that;s what pytrin wrote:

Code: Select all

$values = array();
foreach( $data as $row ) {
      $values[] =  "(" . $row['user_id'] . "," . $row['content'] . ")";
}
if( !empty($values) ) {
     $query = "INSERT INTO `test_table` (user_id,content) VALUES "
               . implode(',',$values);
     mysql_query($query);
}
Your problem is taht part:

Code: Select all

foreach( $data as $row ) {
      $values[] =  "(" . $row['user_id'] . "," . $row['content'] . ")";
}
 
Obviously, foreach(...) should be replaced with your while(....)

The rest of the code ... try it yourself ;)