quickz
07-11-2007, 05:46 PM
I'm trying to go through a mysql database and display all the records that have a duplicate telephone number. The code below seems to only get the first record that has a duplicate but not all the records that have a duplicate.
$query = "SELECT *, count(*) cnt FROM newtab GROUP BY phone HAVING cnt > 1";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$lastname = $row['lastname'];
$firstname = $row['firstname'];
$phone = $row['dayphone'];
echo "Duplicate record - $firstname, $lastname, $phone";
}
$query = "SELECT *, count(*) cnt FROM newtab GROUP BY phone HAVING cnt > 1";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$lastname = $row['lastname'];
$firstname = $row['firstname'];
$phone = $row['dayphone'];
echo "Duplicate record - $firstname, $lastname, $phone";
}