Page is a not externally linkable
- Code, Content, and Presentation
-- Databases
---- php, mysql and pulling by day


rocknbil - 4:32 pm on May 9, 2011 (gmt 0)


What should do it? I think that I am lost.


I have a field that is datetime (mysql) and I am trying to pull the data from that table that is within the last 7 days (PHP).


Substitute "datefield" for whatever that field is named and "table" for the name of the table.

select * from table where datefield >= date_sub(curdate(), interval 7 day);

In PHP, that would be something like

$query = "select * from table where datefield >= date_sub(curdate(), interval 7 day)";
$result = mysql_query($query) or die("Cannot get last 7 days: " . mysql_error());
while ($row = mysql_fetch_array($result)) {
// Row data is stored in $row, whatever the field names are . . . .
echo "<p>ID: " . $row['id'] . " date: " . $row['datefield'] . "</p>";
}


Thread source:: http://www.webmasterworld.com/databases_sql_mysql/4308422.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com