Results 1 to 3 of 3

Thread: Something REALLY simple just isn't working

  1. #1
    Join Date
    Jul 2007
    Location
    England
    Posts
    41
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Exclamation Something REALLY simple just isn't working

    I'm using the following code with no problems:

    PHP Code:
    $query="SELECT * FROM {$table} WHERE id = '1' or id % 24 = 0 LIMIT 0, 90"
    But as soon as I try to order it, it stops working- no data comes back out. This is the code I'm using, and so far as I can see, it's faultless:

    PHP Code:
    $query="SELECT * FROM {$table} WHERE id = '1' or id % 24 = 0 LIMIT 0, 90 ORDER BY created"
    The field "created", before you ask, does definitely exist and does contain data. The field contains timestamps (e.g. 2009-12-17 16:00:12), but I've tried ordering by other INT fields with the same outcome.

    Thanks, mrrsman

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    First, you can start by making the mysql in the right format.
    1. A proper mysql statement ends with a semicolon. (This can also possibly help with security issues by ending a query to not allow injection in some cases.)
    2. Names (columns, tables, etc) need `` quotes-- "backticks", above the tab key. They aren't really required, but it will make it more valid.
    3. Values need quotes ' ' or " "-- since you're using double quotes for the outside here, use single quotes ' ' for the data. This won't matter for numbers in most cases, though.
    4. You can specify DESC or ASC (descending, ascending) after ORDER BY. I don't think it's required, but maybe that would help?

    Anyway, looking at the code the only thing I can think of is the order of it. I think order by and all other specifics must go before the limit. Limit is supposed to end the query, so I think the parser may be confused by "order by" after that.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. The Following User Says Thank You to djr33 For This Useful Post:

    MrRSMan (12-27-2009)

  4. #3
    Join Date
    Dec 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ORDER BY goes before LIMIT. Try this:

    $query="SELECT * FROM {$table} WHERE id = '1' or id % 24 = 0 ORDER BY created LIMIT 0, 90";

Bookmarks

Posting Permissions

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