Jump to content

csv file & database comparison


rbarnett

Recommended Posts

I am trying to compare the contents of a csv file to data from a query.  I would like to to look at the csv file and the results from the query and be able to output where there is a mismatch.

 

The following is the code that I have to read the csv file and the query but I am not sure how to determine the mismatch.  Thank you!

 

include('../moodle_schools_connect.php');

$query = 'SELECT c.id, c.shortname, u.username, u.firstname, u.lastname, u.idnumber FROM testsite_course c 
  LEFT OUTER JOIN testsite_context cx ON c.id = cx.instanceid 
  LEFT OUTER JOIN testsite_role_assignments r ON cx.id = r.contextid 
  LEFT OUTER JOIN testsite_user u ON r.userid = u.id WHERE c.id = 105';

$result = mysql_query($query);

$handle = fopen("enrolments.txt", "r");
echo 'data in file:<br />';
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
    echo $data[0] . ', ' . $data[1] . ', ' . $data[2] . ', ' . $data[3] . '<br />';

}


echo '<br /><br />data from database:<br />';
while ($row = mysql_fetch_array($result, MYSQL_NUM)) 
{

    echo $row[1] . ', ' . $row[2] . ', ' . $row[3] . ', ' . $row[4] . ', '. $row[5] . '<br />';

} 

fclose($handle);

Link to comment
https://forums.phpfreaks.com/topic/159905-csv-file-database-comparison/
Share on other sites

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.