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>"; }} ?> Link to comment https://forums.phpfreaks.com/topic/238240-select-all-from-database-but-only-for-non-duplicates/ 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 Link to comment https://forums.phpfreaks.com/topic/238240-select-all-from-database-but-only-for-non-duplicates/#findComment-1224320 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. Link to comment https://forums.phpfreaks.com/topic/238240-select-all-from-database-but-only-for-non-duplicates/#findComment-1224326 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"; Link to comment https://forums.phpfreaks.com/topic/238240-select-all-from-database-but-only-for-non-duplicates/#findComment-1224331 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.