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>";
   }}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.