Im attempting to use a variable for a column name. I would like to send a variable to the sql string and then assign the result as its own variable to be returned.
function valid_check($test_col,$usr){
global $db;
$sql = mysql_query("SELECT '$test_col' FROM users WHERE user_name = '$usr'", $db);
if ($myrow = mysql_fetch_array($sql))
{do{
$done = $myrow['$test_col']; //i think this is the problem
print ("done is $done and\n<br>column name is $test_col<br>");
}while ($myrow = mysql_fetch_array($sql)); }
else {echo "Sorry, no records were found!";}
}
$test = "testingcolumn";
$login = "anybody";
echo "$test<br>$login<br>";
valid_check($test,$login);
what i get in return is
anybody
testingcolumn
done is testingcolumn and
column name is testingcolumn
Line 3 of that should be "true" as it is the value in the database. My guess is that my problem exist in
$done = $myrow['$test_col'];
How can i pass that field name to replace $test_col on that line?
Thanks
G