The only problem with
$query ="SELECT * from `jos_menu` where `id` = ".'\".$parent.'\";
Is that you missed a few '
:
$query ="SELECT * from `jos_menu` where `id` = ".'\"'.$parent.'\"';
In PHP, a string can either be:
$var = 'This is a string';
Or
$var = "This is a string";
If you want to put "
inside a string that you already started with "
, you need tell PHP that you don't want your second "
to end the string but use the character "
as part of the string itself. This is what \"
does. It tells PHP that Don't give the "
character any special meaning; since normally if you started the string with "
, the next "
would end the string.
\
means remove any "special" meaning to the next character
This only works if the character after the \
would have had special meaning. Some examples:
Suppose we want to print Hello "World". I am a string!
:
$var = "Hello "World". I am a string!";
In this example we will have errors. Since we started the string with "
, the next "
will close the string. So what PHP thinks:
-
"
Start of string
-
Hello
part of string variable.
-
"
Hey, since I saw that the string was started with "
, this must mean the end of it!
-
World"
<-- Error
Stop processing and throw errors.
However, if we write:
$var = "Hello \"World\". I am a string!";
Now, PHP thinks:
-
"
Start of string
-
Hello
part of string variable
-
\
Ah, okay, the next character I should remove any special meaning
-
"
Okay, this is immediately after \
, so I just use it normally, as a "
.
-
World
part of string
-
\
Okay, the next character I will remove any special meaning
-
"
This is now a normal "
-
. I am a string!
- part of string variable.
-
"
Ah! Since the string was started with "
, this must be the ending.
-
;
ends statement.
Hopefully this clarifies things for you.