Page 1 of 1

PHP script for checking duplicates in two MySQL tables

Posted: Thu Feb 12, 2009 6:29 pm
by JKM
Hi there,

I'm having two tables in my database, and I wan't to check if the fruits (ex: banana) is matches any rows in the table "check" in the row "list". If there is any matches, $checkdupe == 'yes ('.$fetch1['amount'].')'; if not, $checkdupe == 'no';.

Code: Select all

<table>
    <tr>
        <td>FRUITS</td>
        <td>check</td>
    </tr>
<?php
mysql_connect('xxx','xxx','xxx') or die("mysql error");
mysql_select_db("xxx") or die("mysql error");
 
$sql = mysql_query("SELECT DISTINCT FROM fruits");
$sql2 = mysql_query("SELECT * FROM check WHERE list='".$fetch['fruit']."'");
$query = mysql_query($sql) or die(mysql_error());
 
while($fetch = mysql_fetch_array($query)) {
?>
    <tr>
        <td><?php echo $fetch['fruit']; ?></td>
        <td><?php $checkdupe; ?></td>
    </tr>
<?
}
?>
</table>
 
Thanks for any help!

Re: PHP script for checking duplicates in two MySQL tables

Posted: Fri Feb 13, 2009 6:37 am
by susrisha
have you forgotten something??
You need to tell us what seems to be the problem with the code..

Re: PHP script for checking duplicates in two MySQL tables

Posted: Fri Feb 13, 2009 7:55 pm
by josh
Select all values, keep an array keyed by primary key, with a value of an integer representing how many times that particular value has been counted, then prune out anything with a value of 1 and run it thru array_keys

Re: PHP script for checking duplicates in two MySQL tables

Posted: Fri Feb 13, 2009 8:00 pm
by VladSun
I doubt you will need any PHP code for doing this, but still I can't understand your DB design.
Could you post your DB schema and some real world values from you tables?

Re: PHP script for checking duplicates in two MySQL tables

Posted: Fri Feb 13, 2009 8:24 pm
by josh
He's trying to normalize data that is not in 2nd NF ( repeating data in rows ), apparently a fruit tracking app lol

Re: PHP script for checking duplicates in two MySQL tables

Posted: Fri Feb 13, 2009 8:43 pm
by VladSun
josh wrote:apparently a fruit tracking app lol
:twisted:

Re: PHP script for checking duplicates in two MySQL tables

Posted: Fri Feb 13, 2009 9:07 pm
by josh
I'll sue JKM after I stage an accident choking to death on an RFID chip from his banana