Help - csv and mysql database compare ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

bidntrade
Forum Commoner
Posts: 33
Joined: Thu Jul 02, 2009 9:54 pm

Re: Help - csv and mysql database compare ?

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Help - csv and mysql database compare ?

Post 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 ;)
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply