Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/84299-solved-order-of-quotes/
Share on other sites

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.