Jump to content

[SOLVED] Help: Checking CSV File Against DB Records


refiking

Recommended Posts

I'm working on a script that checks each record in a csv file against the records in a database table.  When I try this, I get this error:

 

Warning: fread() [function.fread]: Length parameter must be greater than 0. on line 30.

 

Here is the script from lines 1 - 32.  From that point, it just prints the output. 

include 'connect.php';
$change = 1;
$insert = 1;
$fp = fopen('data.txt', 'w');
$handle = fopen("commit.csv", "r");
$sql = mysql_query("SELECT * FROM `members_table`")or die(mysql_error());
while ($row = mysql_fetch_assoc($sql)){
IF ($row['middle_name'] == ""){
$name = $row['first_name'] . " " . $row['last_name'];
}
ELSE {
$name = $row['first_name'] . " " . $row['middle_name'] . " " . $row['last_name'];
}
while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
IF ($name == $data[0]| $row['graduation_year'] == $data[2]){
$add = '<TR><TD><b>' . $data[0] . '</b></TD><TD>' . $data[1] . '</TD><TD>' . $data[2] . '</TD><TD>' . $data[3] . '</TD><TD>' . $data[4] . '</TD><TD>Updated Existing Database Record</TD></TR>' . "\n";
$change++;
}
ELSE{
$add = '<TR><TD><b>' . $data[0] . '</b></TD><TD>' . $data[1] . '</TD><TD>' . $data[2] . '</TD><TD>' . $data[3] . '</TD><TD>' . $data[4] . '</TD><TD>Added New Database Record</TD></TR>' . "\n";
$insert++;
}
fwrite($fp, $add);
fclose($fp);
fclose($handle);
}
}
$filename2 = "data.txt";
$handle2 = fopen($filename2, "rb");
$contents2 = fread($handle2, filesize($filename2));
fclose($handle2);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.