Log in

View Full Version : how to assign variable within query



raihan
04-26-2013, 08:28 AM
Hi,
I have a query like:
$category = "SELECT State_Name FROM Test_State LEFT JOIN Test_Country USING (CountryID) WHERE Country_Name='Spain'";

It's working fine. Instead of giving the Data in 'WHERE' statement, I wish to make like:

var $CName="Spain";
$category = "SELECT State_Name FROM Test_State LEFT JOIN Test_Country USING (CountryID) WHERE Country_Name='$CName'";

I have tried this way, doesn't work. Is it right way to work? Or if not, how I can do like this, please? The query is in PHP.

Also can I make query in Javascript in any way, please let me know as well.

Thanking you in advance.


Raihan

traq
04-26-2013, 01:47 PM
var $CName="Spain";
$category = "SELECT State_Name FROM Test_State LEFT JOIN Test_Country USING (CountryID) WHERE Country_Name='$CName'";

This should work just fine - what error do you get? Try print $category to see what the actual query looks like.