Jump to content


Photo

Need Help to query from now to 7 days ago


  • Please log in to reply
2 replies to this topic

#1 rasputinj

rasputinj
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 10 September 2003 - 12:02 AM

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.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 10 September 2003 - 06:01 AM

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]
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 rasputinj

rasputinj
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 10 September 2003 - 07:15 AM

:lol: Thank you very much for the code help. It works perfectly. I did not know you had to use the ` around the reserved words, someone told me I could use \' which did not work. Once again thanks alot, this was a good learning experience for me.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users