creating a post made since last visit problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lukevrn
Forum Newbie
Posts: 3
Joined: Mon Feb 09, 2009 2:30 pm

creating a post made since last visit problem

Post by lukevrn »

hi,

on a news program i made i want to allow my members to see what new articles were made since they last visited the site. pretty much what i want to do is exactly how phpbb and other bbs programs do.

now looking at them i applied the same method but it doesn't seem to work.

first off i added a column last_visit which would have the last time they visited the site(in time())

then i made it do a search with the following query:.

Code: Select all

SELECT * FROM metal_posts WHERE Date>='$last_visit'
now doing it that displayed 0 results every time no matter what. changed >= to <= just displayed all of the news articles.

so question is, what am i doing wrong?

to let you know all the dates on my program are in time() format so format issue isn't the problem here.

thanks
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: creating a post made since last visit problem

Post by Benjamin »

Code: Select all

 
SELECT * FROM metal_posts WHERE `Date` >='$last_visit'
 
I believe date is a reserved mysql keyword. Try it with backticks. Echo the query and try running it manually to verify that there are no syntax errors. Is $last_visit escaped?
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: creating a post made since last visit problem

Post by mattpointblank »

I wish tools like phpMyAdmin wouldn't let you create columns with reserved variables for names. When I first started out I took hours figuring out that that was the reason my 'desc' (description) column wasn't working, or 'usage'...
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: creating a post made since last visit problem

Post by Weirdan »

astions wrote: I believe date is a reserved mysql keyword.
It is, but it's still allowed as unquoted identifier:
MySQL manual wrote: MySQL allows some keywords to be used as unquoted identifiers because many people previously used them. Examples are those in the following list:
  • ACTION
  • BIT
  • DATE
  • ENUM
  • NO
  • TEXT
  • TIME
  • TIMESTAMP
Post Reply