PDA

View Full Version : Storing result to variable


tenniskid493
02-11-2006, 07:03 PM
How do you store the result set from a SELECT statement into a variable This code works perfectly if I take out the assigning of the variable and just have it immediately echo the result. However, I need it to assign it to a variable and then echo the variable.

$link = mysql_connect('localhost', 'user_name', 'password');
$db_selected = mysql_select_db('Statistics', $link);
$result = mysql_query('SELECT `Name` FROM `Test Stats` WHERE 1 LIMIT 0, 30 ');
if (!$result) {
die('Could not query:' . mysql_error());
}
echo "Name: ";
$nme = mysql_result($result, 0);
echo $nme
mysql_close($link);

Kid Charming
02-11-2006, 10:07 PM
So

echo mysql_result($result, 0);


works, but

$nme = mysql_result($result, 0);
echo $nme;

doesn't? (I'm assuming the missing semicolon is a type in your post, not your script).

tenniskid493
02-11-2006, 10:28 PM
I got it figured out. For some reason it doesnt like the variable $nme but almost every other variable will work. Its wierd but oh well.

karthikeyam
02-16-2006, 10:54 AM
can anybody tell me where should i write this php code n execute
i am totally new to this concept
plzzzzzz its urgent

ronaldb66
02-16-2006, 01:50 PM
karthikeyam,

It would help if you posted in the correct thread...