Grant Holmes Posted January 3, 2008 Share Posted January 3, 2008 I am NOT a programmer and trying to figure out some php stuff, mainly editing other scripts I've had written for me. At times, I succeed, at times, not. One thing that cornfuses me is how you decide what's in quotes. For instance, I have one piece of code that pulls some records for display on a page: $query="SELECT * FROM birthdays WHERE Active='1' AND Event='request'"; THAT I understand. However, I have other code that pulls a range of dates: $query='SELECT *,DATE_FORMAT(Cbirthdate,"%m-%d") AS rbirthdate FROM birthdays where `Active` = 1 AND DATE_FORMAT(Cbirthdate,"%m-%d") >= "'.$fromDay.'" AND DATE_FORMAT(Cbirthdate,"%m-%d") <= "'.$toDay.'"'; Obviously, in both cases I'm not showing all the code for brevity, so if you guys need more, let me know. So in the top example the field name (Active and Event) are plain text and the result I'm looking for are in single quotes. In the later example the field name is in quotes and the result is in plain text. Is this due to the complexity of the second request? Does it matter as long as it's the same throughout the request? Quote Link to comment https://forums.phpfreaks.com/topic/84299-solved-order-of-quotes/ Share on other sites More sharing options...
trq Posted January 3, 2008 Share Posted January 3, 2008 Both your examples are simply strings. Strings surrounded by single quotes can only contain double quotes unless you escape enclosed double quotes and vice versa. This part here.... DATE_FORMAT(Cbirthdate,"%m-%d") will (once passed to mysql_query) execute mysql's DATE_FORMAT function which put simply requires a field as its first argument and a string via which to format the output. Nothing to do with php really. Quote Link to comment https://forums.phpfreaks.com/topic/84299-solved-order-of-quotes/#findComment-429288 Share on other sites More sharing options...
Grant Holmes Posted January 3, 2008 Author Share Posted January 3, 2008 Thank you for your reply... which I think I actually understand!!! So, my code editor attempts to color code things which has REALLY helped me learn when I've messed up code. When I type: $query='SELECT *,DATE_FORMAT(Cbirthdate,"%m-%d") AS rbirthdate FROM birthdays where `Active` = 1 AND Event = request AND.... it is all the same color. However, when I do it like this: $query='SELECT *,DATE_FORMAT(Cbirthdate,"%m-%d") AS rbirthdate FROM birthdays where `Active` = 1 AND 'Event' = request AND... It colors the word "EVENT" differently, suggesting to me that one is incorrect. Quote Link to comment https://forums.phpfreaks.com/topic/84299-solved-order-of-quotes/#findComment-429292 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 Yes because you are using a single quote within a single quote string, and there is no reason to have any quotes around Event. You can use `backticks` around fieldnames if you want. Quote Link to comment https://forums.phpfreaks.com/topic/84299-solved-order-of-quotes/#findComment-429294 Share on other sites More sharing options...
Grant Holmes Posted January 3, 2008 Author Share Posted January 3, 2008 Okay, I see them now. Thanks again. Actually I think those are backticks around ACTIVE and I wasn't paying attention. SOOOOoooooo much to learn! Quote Link to comment https://forums.phpfreaks.com/topic/84299-solved-order-of-quotes/#findComment-429296 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 Active is right, Event was wrong. Quote Link to comment https://forums.phpfreaks.com/topic/84299-solved-order-of-quotes/#findComment-429299 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.