verdrm Posted October 12, 2007 Share Posted October 12, 2007 Is there a way to echo only one thing of a similar name? For example, if I have four posts, two in column (MySQL) 'Title' named 'Post' and two in column 'Title' named 'Draw', so on the PHP page: Post Title Post Post Draw Draw how can I echo just one of each name? I would like the above to look like: Post Title Post Draw Link to comment https://forums.phpfreaks.com/topic/73021-solved-list-help/ Share on other sites More sharing options...
ToonMariner Posted October 12, 2007 Share Posted October 12, 2007 use DISTINCT in your query Link to comment https://forums.phpfreaks.com/topic/73021-solved-list-help/#findComment-368214 Share on other sites More sharing options...
verdrm Posted October 12, 2007 Author Share Posted October 12, 2007 Thanks, that worked! Now, the only problem is that I also have dates next to the post names, which I forgot to mention. Post Title Revision Date Post Oct 12, 2007 7:03:43 PM EDT How do I use DISTINCT when dealing with dates? Link to comment https://forums.phpfreaks.com/topic/73021-solved-list-help/#findComment-368222 Share on other sites More sharing options...
MmmVomit Posted October 12, 2007 Share Posted October 12, 2007 Are the dates the same? Different? Would you like the earliest date? Latest date? Link to comment https://forums.phpfreaks.com/topic/73021-solved-list-help/#findComment-368231 Share on other sites More sharing options...
verdrm Posted October 12, 2007 Author Share Posted October 12, 2007 The dates are different. I would like the most current date. If it helps, my code looks like this: <?php $query = "SELECT DISTINCT title,date FROM info WHERE group_id = '".$_SESSION['ferpa']."' ORDER BY date DESC"; $result = mysql_query($query); ?> <?php while(list($title,$date) = mysql_fetch_array($result, MYSQL_NUM)) { ?> I can get distinct TITLES but the corresponding dates do not echo. Link to comment https://forums.phpfreaks.com/topic/73021-solved-list-help/#findComment-368245 Share on other sites More sharing options...
MmmVomit Posted October 12, 2007 Share Posted October 12, 2007 You could also use a GROUP BY clause and a MAX function on the date field. Link to comment https://forums.phpfreaks.com/topic/73021-solved-list-help/#findComment-368256 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.