ramsri05 0 Newbie Poster

Hello Friends,:)

I want to compare each row in the excel sheet with mysql database table fields in order to eliminate the duplicate entry while inserting data from excel sheet into that particular mysql database table.

Can anybody provide me the logic ? I have added my code here. Please guide me.!

<?php 
if(isset($_POST['submit'])){
$excel_file=$_POST['filename'];
$excel = new Spreadsheet_Excel_Reader($excel_file);
echo "Comparing Excel Sheet and mysql table.<BR>";

//query

$result = mysql_query("SELECT Pam_Participant_Name,Pam_Address_Line1,Pam_Mobile_Phone, Pam_Email_ID,Pam_Date_Of_Birth,Pam_Batch_Name FROM pid_address_master");

if (!$result) {
die("Database query failed: " . mysql_error());
}

// Using returned data
// Logic needed here.!
do{
   $x=1;
    while($x<=$excel->sheets[0]['numRows']) {
   $y=1;
    while($y<=$excel->sheets[0]['numCols']){
     $cond= $row["Pam_Participant_Name"] and $row["Pam_Address_Line1"];
       
     if($excel->sheets[0]['cells'][$x][$y]==$cond and $excel->sheets[0]['cells'][$x][$y]==$row["Pam_Mobile_Phone"]  and $excel->sheets[0]['cells'][$x][$y]== $row["Pam_Email_ID"]){

    echo "<br>Participant Name,address or email or addreess {$excel->sheets[0]['cells'][$x][$y]} found "; 
        }

        $y++;
        }  
       $x++;
      }
    }while ($row = mysql_fetch_array($result));
}
         

else{
 echo "<form action='excel_read_write.php' method='post'>";
 echo "Type file name to import:<br>";
 echo "<input type='file' name='filename' size='20'><br>";
 echo "<input type='submit' name='submit' value='submit'></form>";
}
?>

The above code is checking each cell with the table field but Can anyone guide me how to compare the whole excel row with the Mysql table fields?

Thanks in advance. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.