homepage Welcome to WebmasterWorld Guest from 54.211.219.68
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
php, mysql and pulling by day
scrupply



 
Msg#: 4308422 posted 5:57 pm on May 5, 2011 (gmt 0)

I am trying to pull data by day for last seven days from MySQL. Is this possible? If so, how would I do it?

Thank you,

 

eelixduppy

WebmasterWorld Senior Member eelixduppy us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4308422 posted 8:32 pm on May 5, 2011 (gmt 0)

Just to clarify, do you mean from a single table/relation or from an entire MySQL database (e.g., for backup purposes)?

scrupply



 
Msg#: 4308422 posted 8:43 pm on May 5, 2011 (gmt 0)

The information would come through a single call and then would display out on a page.

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4308422 posted 9:59 pm on May 5, 2011 (gmt 0)

Welcome aboard . . . you have a field with the data type of date or datetime . . .then

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

If you don't have a field with a date/timestamp, you should. :-) Create one.

Alter table tablename add datefield datetime not null default '0000-00-00 00:00:00';

Try to avoid naming fields the same name as reserved words . . . date, datetime, insert, etc.

scrupply



 
Msg#: 4308422 posted 4:53 pm on May 6, 2011 (gmt 0)

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

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4308422 posted 5:17 pm on May 6, 2011 (gmt 0)

Well that should do it. :-)

scrupply



 
Msg#: 4308422 posted 5:27 pm on May 6, 2011 (gmt 0)

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

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4308422 posted 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>";
}

scrupply



 
Msg#: 4308422 posted 10:39 pm on May 19, 2011 (gmt 0)

Thank you, I think that this did it.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved