Using PHP variables wherever you want inside SQL queries
function simplequery($table, $field, $needle, $haystack) {
$result = mysql_query("SELECT $field FROM $table WHERE
$haystack = $needle LIMIT 1;");
if ($result) {
if (mysql_num_rows($result)) {
$row = mysql_fetch_assoc($result);
return $row[$field];
}
} else {
print "Error in query<br />";
}
}
$firstname = simplequery("usertable", "firstname", "ID", $UserID);
Related examples in the same category