help with php code to insert data into mysql db from a csv.
Posted: Thu Oct 16, 2003 9:54 am
Hi
I have a client who has a website that uses a mysql database which is updated from a MS Access db via a csv file.
I want to add some fileds to the database's but when i do the code does not insert the new rows.
Am i right in thinking if i add OR $c==27 in the if statment it will solve my problem.
Thanks guys.
I have a client who has a website that uses a mysql database which is updated from a MS Access db via a csv file.
I want to add some fileds to the database's but when i do the code does not insert the new rows.
Am i right in thinking if i add OR $c==27 in the if statment it will solve my problem.
Thanks guys.
Code: Select all
// Initialise database
include "../initialise.php";
if ($Parlours=="on") {
echo "<P>Imprting Parlours:</P>\n";
$row = 0;
//this line may need to be altered to reflect server's file system
$fp = fopen ("../csv/Parlours.csv","r");
$deleteres=mysql_query("DELETE from Parlours");
//read in each line from csv file
while ($data = fgetcsv ($fp, 1000, "¬")) {
$num = count ($data);
$qry="INSERT INTO Parlours VALUES(""";
//for each record to be input, contruct query
for ($c=0; $c<$num; $c++) {
$importedї$row]ї$c]=$dataї$c];
if ($c==5 OR $c==6 OR $c==7 OR $c==8 OR $c==11 OR $c==15 OR $c==19 OR $c==20 OR $c==21 OR $c==22 OR $c==23 OR $c==24
OR $c==25 OR $c==26 OR $c==27) {
if ($importedї$row]ї$c]==1) {
$importedї$row]ї$c]="yes";
}
else {
$importedї$row]ї$c]="no";
}
}
if ($c==11 OR $c==12 OR $c==13) {
$importedї$row]ї$c]=chop($importedї$row]ї$c]);
}
$qry=$qry.","".$importedї$row]ї$c].""";
}
$qry=$qry.")";
//print $qry."\n";
//print "\n";
$insertres=mysql_query($qry);
$row++;
}
fclose ($fp);
}