I was wondering if anyone had any input on how to create a reusable query in a function.
Here is my original:
$query = "SELECT DISTINCT firstName FROM myTable WHERE lastName='$lastName'";
$result = mysql_query($query, $connection);
//.... rest of code goes here
I want to use a function since I will be using this a number of times with different variables in place. Here is what I was thinking, something like this....
function getSelection($var1, $var2)
{
$query = "SELECT DISTINCT $var1 FROM myTable WHERE $var2='$var2'";
$result = mysql_query($query, $connection);
//.... rest of code goes here
}
getSelection("firstName", "lastName");
This is where I am seeing the problem...
$var2='$var2'
when the function pulls the var lastName into it, is there a way I can get it to read the string "lastName" as a var instead of as a string so it would read $lastName?
essentially the function should read :
lastName='$lastName'
Any ideas on how this can be accomplished, thanks for your time.