Firstly, do you just mean to print a variable on screen? I will assume so. Here's an example I created in PHP/MySQL (simplified for demonstration purposes). You should be able to adapt to your needs as required.
$table = "test";
$query = "SELECT * FROM $table WHERE field1='test' ORDER BY field2";
$result = mysql_query($query);
$data_row = mysql_fetch_array($result, MYSQL_ASSOC);
The above will return the first record of data from your query. Then to extract a specific field of data from that record into the variable $test_variable, you can use the following:
$test_variable = $data_row['field1']; (field1 is the name of your field/column)
Then you can do whatever you want with $test_variable.
I hope that's what you're looking for.