Jump to content

Archived

This topic is now archived and is closed to further replies.

pixeltrace

query problem

Recommended Posts

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!

Share this post


Link to post
Share on other sites
[!--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 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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites
[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?!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.