Jump to content

Need Help to query from now to 7 days ago


rasputinj

Recommended Posts

I am running phpnuke with mysql and I am try to modify a top 15 module that pulls the 15 most read stories. I would like to modify it to only show the most read stories in the last 7 days

 

Here is the current query

 

 

select sid, title, counter from ".$prefix."_stories  order by counter DESC limit 0,$top", $dbi);

 

the field Time is setup in this format 2003-09-02 11:40:46

 

I had tried to add this to the query before order by

 

Where time between now() and now() - interval 7 days

 

I do not get an error when I run, I just get no results. Is Time a reserved word? Do I need quotes around it, and can I use interval with now()?

 

I am a newbie when it comes to Mysql, I am trying to learn though. Any help would be appreciated.

Link to comment
Share on other sites

Time is reserved, but allowed as a fieldname. Use backticks ``.

 

Try

 

[php:1:26a151707a]<?php

$day_7 = date(\'Y-m-d\', strtotime(\'-7 days\'));

 

$query = \"select sid, title, counter from \".$prefix.\"_stories

where `time` > \'$day_7\'

order by counter DESC limit 0,$top\";

?>[/php:1:26a151707a]

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.