PHP script for checking duplicates in two MySQL tables
Posted: Thu Feb 12, 2009 6:29 pm
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';.
Thanks for any help!
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>