Results 1 to 2 of 2

Thread: how to assign variable within query

  1. #1
    Join Date
    Feb 2013
    Posts
    49
    Thanks
    25
    Thanked 1 Time in 1 Post

    Default how to assign variable within query

    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

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,634
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by raihan View Post
    PHP Code:
    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.

Similar Threads

  1. Assign dynamic value to variable
    By Rachele7 in forum JavaScript
    Replies: 1
    Last Post: 07-18-2011, 10:57 AM
  2. Assign an input value to become the name of the var
    By sniperman in forum JavaScript
    Replies: 3
    Last Post: 01-16-2011, 01:06 AM
  3. Assign z-index with javascript
    By mayamacd in forum JavaScript
    Replies: 0
    Last Post: 06-10-2009, 07:30 PM
  4. Replies: 1
    Last Post: 11-14-2008, 06:00 PM
  5. Assign id upon elementCreate
    By devinrayolsen in forum JavaScript
    Replies: 1
    Last Post: 05-25-2008, 09:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •