Jump to content

select all from database, but only for non duplicates


searls03

Recommended Posts

how can I modify this code so that it pulls all results from database, but if $event has duplicates, it wont display all the extras, only one?

 

<?php
// Query member data from the database and ready it for display
include_once "secure/connect_to_mysql.php";

if(!isset($_GET['id']))
{

   $query = "SELECT image, event, name, id, site FROM pictures";
   $result = mysql_query($query) or die('Error : ' . mysql_error());
  
   // create the article list

   while($row = mysql_fetch_array($result, MYSQL_NUM))
   {
      list($image, $event, $name, $id, $site) = $row;
  
      $content .= "<li><a href='$site'>$event</a></li>";
   }}
?>

What do you define as a duplicate? All the values the same for two records or just the name duplicate, or what? If you have records with ALL the same values - and you don't want them I would say you have a problem in your application where it is not preventing the duplicates from being added.

 

But, if you only consider them duplicates for a finite number of fields you can use GROUP BY on those fields.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.