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 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2012
    Location
    France
    Posts
    58
    Thanks
    15
    Thanked 0 Times in 0 Posts

    diference between `takenAt`and 'takenAt'

    I am using Aptana Studio 3 on a Mac to write queries to get data out of a MySQL DB. First I build the SQL query in the SQL box of PHPmyadmin, when it works I convert to php code in PHPmyadmin and paste into aptana and adjust the variables. I noticed that the ' from PHPmyadmin looks diferent to that simply typed in aptana and sometimes the query fails. I guess ts something to do with the the ASCII codes - can someone enlighten me? Below is code that does work followed by some that doesn't.
    Code:
    $result = mysql_query($sql = "SELECT * FROM `orders` 
    		WHERE `takenAt`= '{$_POST['takenAt']}' 
    		and `collectDate` BETWEEN '{$_POST['date1']}' AND '{$_POST['date2']}' 
    		and `specialCare`= 'yes'
    		ORDER BY `collectDate`", $connection );
    Code:
    $result = mysql_query($sql = "SELECT * FROM `orders` 
    		WHERE 'takenAt'= '{$_POST['takenAt']}' 
    		and `collectDate` BETWEEN '{$_POST['date1']}' AND '{$_POST['date2']}' 
    		and `specialCare`= 'yes'
    		ORDER BY `collectDate`", $connection );
    A talent for speaking differently, rather than for arguing well, is the chief instrument of cultural change. Richard Rorty

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    `takenAt` is a field. That would compare the value in takenAt to the $_POST['takenAt'].
    'takenAt' is a string. That would compare the string takenAt to the value of $_POST['takenAt'].
    MySQL uses accent grave to mark field properties. This is only required if you have chosen a property name that is a part of the reserved words list.

  • Users who have thanked Fou-Lu for this post:

    oddshoes (11-23-2012)

  • #3
    New Coder
    Join Date
    Aug 2012
    Location
    France
    Posts
    58
    Thanks
    15
    Thanked 0 Times in 0 Posts
    I see, so I could leave the accent grave out where defining the field so long as I don't use reserved words as field names, and the query fails if I try to use it as a string identifier - teach me to use cut and paste so much!
    thanks
    A talent for speaking differently, rather than for arguing well, is the chief instrument of cultural change. Richard Rorty

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,029
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    You also need the accent grave (I call them "tick marks") if your field or table names contain illegal characters, such as spaces and hyphens. And. yes, there are many people who like to put spaces in field names.
    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.

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,592
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Quote Originally Posted by Old Pedant View Post
    And. yes, there are many people who like to put spaces in field names.

    but those who learn how to use databases properly will substitute an underscore for the space and so avoid all the issues spaces in field names introduces.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,029
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    Sadly, there are many who create reports directly from a database and, because they want their column names to "look pretty", they put spaces and many other illegal characters in the field names (dashes, periods, octothorps, currency symbols, and more).

    You would be amazed at some of the places I have seen this. In companies with DBAs who should know better but who take a short cut to make the boss happy.

    On the rare occasions that I've done something similar (almost always I will instead produce the report via ASP/JSP/et al.), *at least* I have done it via the use of aliases, so that only in the final SELECT do I need to use crap like this.
    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.


  •  

    Posting Permissions

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