searls03 Posted June 2, 2011 Share Posted June 2, 2011 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>"; }} ?> Quote Link to comment Share on other sites More sharing options...
teynon Posted June 2, 2011 Share Posted June 2, 2011 This is a mysql question, and i'm sure there are better options, but you could use GROUP BY event Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 2, 2011 Share Posted June 2, 2011 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. Quote Link to comment Share on other sites More sharing options...
Drummin Posted June 2, 2011 Share Posted June 2, 2011 $query = "SELECT image, name, id, site, DISTINCT(event) FROM pictures"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.