Results 1 to 3 of 3

Thread: Is this wrong???

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    32

    Is this wrong???

    Here is the code that I used and found not working.

    $t=time();
    $t-=84600;
    $q="select * from flash where time>=".$t." order by time desc limit 10";
    $result=mysql_query($q);

    whts wrong with it???

    The query returns all the rows in the table irrespective of the constraint.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Is this wrong???

    why not just define $t as time() - 84600 in the first place?

    try enclosing your variable in the query with single quotes, (ie: time>='" . $t . "') just to be safe. if that doesn't work, print the query out and see what it looks like, and make sure it runs in mysql itself or phpmyadmin and returns what you want. the query itself looks fine.
    Like Archer? Check out some Sterling Archer quotes.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Is this wrong???

    If the "time" column is of type TIMESTAMP, DATE or DATETIME, it expects a MySQL timestamp value, not the Unix timestamp PHP uses. Try this:
    Code:
    $q="select * from flash where time>=FROM_UNIXTIME($t) order by time desc limit 10";
    Note that variables in double-quoted strings are automatically replaced; no need to stop the string.

    That said, the code is WRONG, WRONG, WRONG!!! It doesn't use parametrized queries and if you don't consistently use them, one day you'll write some SQL injection holes.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width