Results 1 to 2 of 2

Thread: SQL Variables

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default SQL Variables

    In SQL how can values be assigned to variables for example


    Code:
    Select firstname, lastname from users where email like 'john@example.com'
    
    --assign firstname and lastname to variables
    
    Update SomeNameAssociation
    set firstnameis = @Fname
    where lastname = @Lname
    Corrections to my coding/thoughts welcome.

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,689
    Thanks
    82
    Thanked 89 Times in 87 Posts

    Default

    Code:
    $get_list = "SELECT firstname, lastname FROM users WHERE email LIKE '%john@example.com%'";
    $get_list_res = mysql_query($get_list,$conn) or die(mysql_error());
       while ($list_info = mysql_fetch_array($get_list_res)) {
          $firstname = $list_info['firstname'];
          $lastname = $list_info['lastname'];
    }
    This only answers the question you asked. I am guessing you know how to update your other table now that the values pulled from the first table in your database.
    To choose the lesser of two evils is still to choose evil. My personal site

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
  •