pixeltrace Posted March 7, 2006 Share Posted March 7, 2006 guys,i need help, i dont know how to do this.how will you set your sql query in such a way that i will just show thelast 5 data by date.lets say, today is march 7, it will just show the 5 data from march 7 onwardsand once the date has expired or when there is no more data to show itwill print a comment saying "no current events"need help.thanks! Quote Link to comment https://forums.phpfreaks.com/topic/4331-query-problem/ Share on other sites More sharing options...
webwiese Posted March 7, 2006 Share Posted March 7, 2006 [!--quoteo(post=352514:date=Mar 7 2006, 03:11 PM:name=pixeltrace)--][div class=\'quotetop\']QUOTE(pixeltrace @ Mar 7 2006, 03:11 PM) [snapback]352514[/snapback][/div][div class=\'quotemain\'][!--quotec--]guys,i need help, i dont know how to do this.how will you set your sql query in such a way that i will just show thelast 5 data by date.lets say, today is march 7, it will just show the 5 data from march 7 onwardsand once the date has expired or when there is no more data to show itwill print a comment saying "no current events"need help.thanks![/quote]Hi,$query = "SELECT ...... FROM ..... WHERE .... ORDER BY date LIMIT 5"Greetswebwiese Quote Link to comment https://forums.phpfreaks.com/topic/4331-query-problem/#findComment-15067 Share on other sites More sharing options...
pixeltrace Posted March 8, 2006 Author Share Posted March 8, 2006 thanks man! it work.another question, i need a script that will say that if there are no data on a specific date, lets say today, mar 9, 2006 there will be a note saying that"no new updates"may i know what the script is? because i honestly dont have an idea where to start.hoping for your help on this.thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/4331-query-problem/#findComment-15444 Share on other sites More sharing options...
webwiese Posted March 15, 2006 Share Posted March 15, 2006 [!--quoteo(post=352903:date=Mar 8 2006, 06:18 PM:name=pixeltrace)--][div class=\'quotetop\']QUOTE(pixeltrace @ Mar 8 2006, 06:18 PM) [snapback]352903[/snapback][/div][div class=\'quotemain\'][!--quotec--]thanks man! it work.another question, i need a script that will say that if there are no data on a specific date, lets say today, mar 9, 2006 there will be a note saying that"no new updates"may i know what the script is? because i honestly dont have an idea where to start.hoping for your help on this.thanks again![/quote][code]# First step: Receiving your 5 last data$query = "SELECT * FROM ... WHERE ... ORDER BY date DESC LIMIT 5";$result = mysql_query($query, $databaseconnection);while (@$row = mysql_fetch_array($result)) { # Do something with your received data} // while# Second step: What is the highest date in db?$query = "SELECT MAX(date) AS max FROM ... ";$result = mysql_query($query, $databaseconnection);$row = mysql_fetch_array($result);# date - format in db is datetime?if ($row[max] < date("Y-m-d H:i:s")) { echo "no new updates";} // if[/code]Code is written without deeper thinking and testing ... sorry, no time ! ;-)webwiese Quote Link to comment https://forums.phpfreaks.com/topic/4331-query-problem/#findComment-17725 Share on other sites More sharing options...
keeB Posted March 15, 2006 Share Posted March 15, 2006 [code]$query = "SELECT * FROM ... WHERE date = $dateToCheck ORDER BY date DESC LIMIT 5";$result=mysql_query($query);if (mysql_num_rows($result == 0)) die ("no results found for " . $dateToCheck);[/code]Make sense?! Quote Link to comment https://forums.phpfreaks.com/topic/4331-query-problem/#findComment-17741 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.