SELECT 'variable for column'?
Posted: Sat Jun 24, 2006 2:11 pm
Ok, I hope I can explain this good.
The first part is to retreive a specific value from a table. This works fine and returns what I want. In fact, with the constraints, it will only return ONE variable eg $array_variable[0]
This works fine. Now, with $array_variable[0], this represents the NAME of a column in another table and I want to retreive the value from that table.
This does not work.
But it's my example. See where '$array_variable' is the variable retreived from the first query but it needs to identify a column in the second query. If this works, it will retreive only ONE variable again. And thats what I need it to do.
So the big question is, can you use a variable to identify a column in a MySQL QUERY?
I hope I posted this right
The first part is to retreive a specific value from a table. This works fine and returns what I want. In fact, with the constraints, it will only return ONE variable eg $array_variable[0]
Code: Select all
$array_variable = mysql_fetch_array(mysql_query("SELECT this_column FROM table WHERE this_row='$this_row' AND id='$id'"));Code: Select all
$new_variable = mysql_fetch_array(mysql_query("SELECT '$array_variable' FROM new_table WHERE this_row = '$this_row'"));But it's my example. See where '$array_variable' is the variable retreived from the first query but it needs to identify a column in the second query. If this works, it will retreive only ONE variable again. And thats what I need it to do.
So the big question is, can you use a variable to identify a column in a MySQL QUERY?
I hope I posted this right