MYSQL PHP DUPLICATES?

  • Thread starter Thread starter Creative C
  • Start date Start date
C

Creative C

Guest
Can anybody help me to list all the duplicate records from a database. An need to show how many times its duplicated

Database name : CUSTOMERS
Table name : HQ
Table fields : ID (primary), NO, ORDER

Eg: of data in the field

ID NO ORDER
1 468536 CHICKEN
2 852368 CHICKEN
3 588562 BEEF
4 995562 MUTTON


Result should be
CHICKEN (2)
BEEF (1)
MUTTON (1)
 
<?php
// Create your query
$query = "SELECT HQ.ORDER, COUNT(HQ.ORDER) AS COUNT FROM HQ";

// Perform Query
$result = mysql_query($query);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
**$message = 'Invalid query: ' . mysql_error() . "\n";
**$message .= 'Whole query: ' . $query;
**die($message);
}

// Use result
// Attempting to print $result won't allow access to information in the resource
// One of the mysql result functions must be used
// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.
while ($row = mysql_fetch_assoc($result)) {
**echo $row['ORDER'] . " (" . $row['COUNT'] . ")";
}
?>
 
Back
Top