Jump to content

query problem


pixeltrace

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.