Jump to content


Photo

query problem


  • Please log in to reply
4 replies to this topic

#1 pixeltrace

pixeltrace
  • Members
  • PipPipPip
  • Advanced Member
  • 577 posts

Posted 07 March 2006 - 02:11 PM

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 the
last 5 data by date.
lets say, today is march 7, it will just show the 5 data from march 7 onwards
and once the date has expired or when there is no more data to show it
will print a comment saying "no current events"

need help.
thanks!


#2 webwiese

webwiese
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 07 March 2006 - 02:26 PM

[!--quoteo(post=352514:date=Mar 7 2006, 03:11 PM:name=pixeltrace)--][div class=\'quotetop\']QUOTE(pixeltrace @ Mar 7 2006, 03:11 PM) View Post[/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 the
last 5 data by date.
lets say, today is march 7, it will just show the 5 data from march 7 onwards
and once the date has expired or when there is no more data to show it
will print a comment saying "no current events"

need help.
thanks!
[/quote]


Hi,

$query = "SELECT ...... FROM ..... WHERE .... ORDER BY date LIMIT 5"

Greets
webwiese

#3 pixeltrace

pixeltrace
  • Members
  • PipPipPip
  • Advanced Member
  • 577 posts

Posted 08 March 2006 - 05:18 PM

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!


#4 webwiese

webwiese
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 15 March 2006 - 07:47 AM

[!--quoteo(post=352903:date=Mar 8 2006, 06:18 PM:name=pixeltrace)--][div class=\'quotetop\']QUOTE(pixeltrace @ Mar 8 2006, 06:18 PM) View Post[/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]


# 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 is written without deeper thinking and testing ... sorry, no time ! ;-)

webwiese


#5 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 15 March 2006 - 08:37 AM

$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);

Make sense?!

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users