Log in

View Full Version : SQL Variables



bluewalrus
11-11-2010, 04:14 PM
In SQL how can values be assigned to variables for example




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

james438
04-22-2011, 03:00 AM
$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.