lawrence_dev
asked on
How do I fix this error with quotation marks?
How do I correctly structure thsee quotation marks in this string?? ' . $supplier['table'] . 'Cats'' I have attempted several different ways with single and double quotes and still get errors.
Thanks!
LEFT JOIN ' . $supplier['table'] . 'Cats'' USING (Category)');
Thanks!
ASKER
Julian,
I am unable to get the code to work with the above examples. Here is the full string for the Left Join.
Thanks!
I am unable to get the code to work with the above examples. Here is the full string for the Left Join.
$query3 = $conn2->query("SELECT DISTINCT SubCategory, Category, SubCatID FROM " . $supplier['table'] . ".SubCats LEFT JOIN " . $supplier['table'] . ".Cats USING (Category)");
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You gave us this (double single quotes - was that supposed to be single double quotes?)
If you used the suggestion above and put {} around your strings and not use concatenation you would have got this
BTW $supplier['table'] is misleading - is that meant to be a database reference with .cats and .subcats being the actual tables?
LEFT JOIN ' . $supplier['table'] . 'Cats'' USING (Category)');
Now you give this$query3 = $conn2->query("SELECT DISTINCT SubCategory, Category, SubCatID FROM " . $supplier['table'] . ".SubCats LEFT JOIN " . $supplier['table'] . ".Cats USING (Category)");
That's not the same codeIf you used the suggestion above and put {} around your strings and not use concatenation you would have got this
$query3 = $conn2->query("SELECT DISTINCT SubCategory, Category, SubCatID FROM {$supplier['table']}.SubCats LEFT JOIN {$supplier['table']}.Cats USING (Category)");
My preference would have been using HEREDOC as follows$sql = <<< QUERY
SELECT DISTINCT
SubCategory,
Category,
SubCatID
FROM
`{$supplier['table']}.SubCats` LEFT JOIN `{$supplier['table']}.Cats`
USING
(Category)
QUERY;
$query3 = $conn2->query($sql);
Much easier to see what is going on.BTW $supplier['table'] is misleading - is that meant to be a database reference with .cats and .subcats being the actual tables?
Option 1
Escape with \
Open in new window
Option 2
Use double quotes for the string
Open in new window
Option 2aUse double quotes for the string and embed var with { }
Open in new window
Option 3 [PREFERRED]Use HEREDOC. Allows use of both single and double quotes without escaping and embedding of variables
Open in new window