Jump to content

[SOLVED] Showing the latest entries from the latest day


pets2soul

Recommended Posts

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!!

 

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.

 

 

:P 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...)

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
}
?>

Archived

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

×
×
  • 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.