Results 1 to 5 of 5

Thread: count(*) problem

  1. #1
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default count(*) problem

    Hi all,
    I've been grappling with this for a few days now:

    Quote Originally Posted by mySQL
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=1 AND `expires` >1293989873' at line 1
    this is the full query:
    Code:
    SELECT count( * ) FROM `table` WHERE `show` =1 AND `expires` >1293989498
    Odd thing is, this query works fine from phpMyAdmin, but fails from my script. Any ideas?

    thanks!
    Last edited by traq; 01-06-2011 at 08:56 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,161
    Thanks
    44
    Thanked 3,238 Times in 3,199 Posts
    Blog Entries
    12

    Default

    I know next to nothing about this, but it strikes that may be a shortcut unavailable outside phpMyAdmin where presumably a context of some sort has already been established, see:

    http://www.codingforums.com/showthre...767#post440767

    and the posts that immediately follow it for more of a hint at what I'm talking about. There, though it doesn't figure in the resolution of the original question, a context must be established.

    The same is true of various debugging tools in javascript. What you may type there and the results you get vary from what can be done in actual script. The results can usually be obtained, but more code is often required.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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

    traq (01-02-2011)

  4. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Thanks, John,

    Apologies, but this turned out to be a completely unrelated problem. Other components of the script were outputting a malformed "LIMIT" statement, which sometimes gave an empty result and sometimes gave a syntax error.

    Thanks for your help anyway!

  5. #4
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    try
    Code:
    SELECT count( * ) FROM `table` WHERE show=1 AND expires>1293989498

  6. #5
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    thanks, but I already solved this. It was a typo elsewhere in the query.

    And, just to point out, using backticks around column names is good practice - and sometimes, quite worth your while.

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
  •