Re: a LITTLE bug with my CSV importer :-)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey there Roger,

I just put that in (Will keep it in anyway) but I get the same problem.  Could it be there's some kind of illegal char in one of the array fields?  If so, how can I do checking and fix bad characters when going through the array?  I know if I remove the LoDesc fields (Which is $data[15]; if I remember correctly) it imports over 880 fields, but when that's in it only imports 92 - but I have no idea how to correct bad characters they may have put in the file (I have no control over the characters they use - sigh).

I really appreciate your help on this.

Regards

Chris
  may want to try this also (instead of stating a size)...

  filesize($filename)

  This:

while ($data = fgetcsv ($fp, 10000, $d)) {Would be this:

while ($data = fgetcsv ($fp, filesize($userfile), $d)) {
  Let me know...
  Roger


  Chris Payne wrote:

Hi there everyone,

OK So I kind of have my CSV utility working nicely, except for one thing - if I import the file with PHPMyADMIN it imports over 1000 rows (Which is correct) but with the below code on the same file, it's only importing 92 rows, can anyone see anything obvious that's wrong?  I think it could be the MySQL query, as I have a count statement which counts the number of rows in the loop and it counts correctly and if I print the data on the screen it prints the data correctly, just when it writes to the DB argghhh i'm going nuts, i've been trying hard to figure it out without hasstling the group (Sorry).

$d = "|"; // fields delimiter
$fp = fopen ($userfile, "r");
while ($data = fgetcsv ($fp, 10000, $d)) {
  $num = count ($data);
   $row++;

$count ++;

mysql_query ("INSERT INTO import (id,BranchReference,address1,Location,Location2,Postcode,Price,Offers,Bedrooms,Receptrooms,period,Proptype,spare1,Propstatus,ShortDescription,LoDesc,PictureRef1,Bullets,Field1,Field2,Field3,Field4,Field5,Field6,Sale) 
              VALUES ('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[9]','$date[10]','$data[11]','$data[12]','$data[13]','$data[14]','$data[15]','$data[16]','$data[17]','$data[18]','$data[19]','$data[20]','$data[21]','$data[22]','$data[23]','$data[24]') ");

};
echo $count;

fclose ($fp);

Thanks for any help

Regards

Chris
  

-- 
...and I say unto you, the Geek shall inherit the earth.

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux