Daguse Posted April 28, 2006 Share Posted April 28, 2006 I am looking a for a way to echo out data from a DB in a loop. However I do not want to display repeat info. I will be pulling Dates. So if I have pulled say September 2005 two times in a row and November 2005 4 times in a row. I want it only to echo September only once and November only once. Can any one help me out. Link to comment https://forums.phpfreaks.com/topic/8602-selcetive-list-loopping/ Share on other sites More sharing options...
toplay Posted April 28, 2006 Share Posted April 28, 2006 You can retrieve unique rows from a table by using SELECT DISTINCT column_name, or use the GROUP BY clause.However, if you can't use those for what you need, then you have to at least sort the rows using ORDER BY. Then it's just a matter of determining when the data has changed.Example:[code]// open, select DB, and query table using order by$saved_value = ''; // Initialize to something that the data won't containwhile ($row = mysql_fetch_assoc($result)) { // Determine if data has changed and display one time (heading) if ($row['column_name'] != $saved_value) { echo 'Heading: ', $row['column_name'], '<br/>'; $saved_value = $row['column_name']; } // Display other column data echo $row['name'];}[/code] Link to comment https://forums.phpfreaks.com/topic/8602-selcetive-list-loopping/#findComment-31557 Share on other sites More sharing options...
Daguse Posted April 28, 2006 Author Share Posted April 28, 2006 Thank you I will read up on my MySQL querys and try the SELECT DISTINCT column_name, or the GROUP BY clause. Link to comment https://forums.phpfreaks.com/topic/8602-selcetive-list-loopping/#findComment-31725 Share on other sites More sharing options...
Daguse Posted April 30, 2006 Author Share Posted April 30, 2006 Ok I need you guys help. I can't seem to find the syntax for SELECT DISTINCT and GROUP BY. Link to comment https://forums.phpfreaks.com/topic/8602-selcetive-list-loopping/#findComment-32112 Share on other sites More sharing options...
toplay Posted April 30, 2006 Share Posted April 30, 2006 Select syntax from manual:[a href=\"http://dev.mysql.com/doc/refman/4.1/en/select.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/4.1/en/select.html[/a]Tutorial:[a href=\"http://www.keithjbrown.co.uk/vworks/mysql/mysql_p3.shtml\" target=\"_blank\"]http://www.keithjbrown.co.uk/vworks/mysql/mysql_p3.shtml[/a] Link to comment https://forums.phpfreaks.com/topic/8602-selcetive-list-loopping/#findComment-32189 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.