Listing duplicate records

3 posts by 2 authors in: Forums > CMS Builder
Last Post: February 2, 2010   (RSS)

Re: [eduran582] Listing duplicate records

By Damon - February 2, 2010

Hi,

There is array_unique function to show only unique values but I'm not aware of a function to only show duplicates.

It could be done with some custom coding.

What exactly are you trying to do?
Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Damon] Listing duplicate records

Hi Damon,

Thanks for answering. Basically, I was trying to search a mySQL database to find the number of instances of a record based on the [unique] information contained in one of the fields. Example: Finding how many times a user's phone number occurs when the record is accessed. All I really needed was the count.

[tongue] (My) Solution:

<?php
$phon_num = '123-456-7890'; // can also be a variable brought over from another file via 'include' for multiple look-ups
$con = mysql_connect("localhost","database","table");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);
$query = "SELECT count(phone_number) FROM table WHERE phone_number='$phon_num'";
$pnums= mysql_result (mysql_query ($query), 0);
// $pnums = the number of times the phone number occurs

echo 'The phone number '.$phon_num. ' occurs '.$pnums. 'times';
?>

Again, thanks for answering! [;)]

Eric