pets2soul Posted July 7, 2008 Share Posted July 7, 2008 Hello there, The more pages I'm working, more questions popped up...and I messed up my previous post...so here I am extracting this new question under a new topic... I'm working on a news archive type of website, what I'm trying to do now is to show only the article entries from the latest day...this is what I got in mind: $result=mysql_query("SELECT * FROM news WHERE date BETWEEN '2008-01-01' AND '2008-12-31' GROUP BY date ORDER BY fname DESC LIMIT 1"); I have "date" as one of my database column, in the format of yyyy-mm-dd. However, if I set the LIMIT to be 1, only the ONE last entry would be shown, but what do I do if I have more than one entries made in the same day, and I want to show them all? And if I remove the LIMIT 1, all the entries made from 2008-01-01 to 2008-12-31 would be shown, that's not what I want to do.... What I missed in the code? Thanks thanks!! Link to comment https://forums.phpfreaks.com/topic/113515-solved-showing-the-latest-entries-from-the-latest-day/ Share on other sites More sharing options...
cooldude832 Posted July 7, 2008 Share Posted July 7, 2008 you should abuse mysql for its powers and use a proper date field type such as DATE or my favorite DATETIME that being said you query looks more like <?php $q = "select * from `news` where date > ".date("Y-m-d")." ORDER BY Date"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); ?> since its the last day the date will default to "today" and by not defining a time it will find everything from midnight today till end of today thus achieving what you want. Link to comment https://forums.phpfreaks.com/topic/113515-solved-showing-the-latest-entries-from-the-latest-day/#findComment-583308 Share on other sites More sharing options...
pets2soul Posted July 7, 2008 Author Share Posted July 7, 2008 I guess I didn't describe my question well... In this particular page I'm working on...I want it to show the latest entry or entries I have made on my last updating date. For example, say...I made ONE article entry on 2008-07-03, then I want the page to show only this entry... and then...I made THREE entries on 2008-07-06, and I want the page to show the 3 entries... That's why I tried GROUP BY date, but I guess what caught me is...how do I define "last updating date" in php code? and how do I tell it to show only the entry or entries from the last updating date? (The website is not updating daily...) Link to comment https://forums.phpfreaks.com/topic/113515-solved-showing-the-latest-entries-from-the-latest-day/#findComment-583338 Share on other sites More sharing options...
cooldude832 Posted July 7, 2008 Share Posted July 7, 2008 well the last updating day is still going to be a greater by qurey by we need to figure out what that day is first so lets do this <?php # this query returns the last "date" from the table"; $q = "select date from `news` Order by Date DESC LIMIT 1"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); $row = mysql_fetch_assoc($r); $last_date = $row['date']; #now we use $last_date to get the data from that day $q = "Select * from `news` Where date > '".date("Y-m-d",strtotime($last_date))."'"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); while($row = mysql_fetch_assoc($r)){ #echoing out days stuff } ?> Link to comment https://forums.phpfreaks.com/topic/113515-solved-showing-the-latest-entries-from-the-latest-day/#findComment-583711 Share on other sites More sharing options...
pets2soul Posted July 8, 2008 Author Share Posted July 8, 2008 Fantastic!! It's working like a charm now!!! I finally learned to use more than one query... Thank you, cooldude832, you are COOL! Link to comment https://forums.phpfreaks.com/topic/113515-solved-showing-the-latest-entries-from-the-latest-day/#findComment-584152 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.