Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Query Formating

  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Query Formating

    Hey guys a quick question here... I wanted to know if the query below is correct in terms of its syntax I have not tested the query yet. I have a lot of thing to change to look like this and I wanted to make sure i was on point first.

    PHP Code:
    $strQuery3 "SELECT SUM($myStr3) AS totalPings "
                       
    " FROM auto_pings "
                       
    " WHERE $myStr3 = 1 AND date BETWEEN '$form' AND '$to' "

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,027
    Thanks
    79
    Thanked 4,436 Times in 4,401 Posts
    Um...$form? I suspect you mean $from.

    Yes, that should work. But you would get the same results from doing
    Code:
    $strQuery3 = "SELECT COUNT(*) AS totalPings "
                       . " FROM auto_pings "
                       . " WHERE $myStr3 = 1 AND `date` BETWEEN '$from' AND '$to' ";
    since the SUM of a bunch of 1's is obviously going to be the same as the count of that same bunch.

    Note that I enclosed date in `...`. It's not strictly required, but it's a good idea, since date is a builtin function in MySQL.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Um...$form? I suspect you mean $from.

    Yes, that should work. But you would get the same results from doing
    Code:
    $strQuery3 = "SELECT COUNT(*) AS totalPings "
                       . " FROM auto_pings "
                       . " WHERE $myStr3 = 1 AND `date` BETWEEN '$from' AND '$to' ";
    since the SUM of a bunch of 1's is obviously going to be the same as the count of that same bunch.

    Note that I enclosed date in `...`. It's not strictly required, but it's a good idea, since date is a builtin function in MySQL.

    Awesome thank you so much!!!
    Last edited by guelphdad; 12-20-2011 at 04:23 PM. Reason: secondary question had been split off into its own thread.


  •  

    Posting Permissions

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