Lamped's solution will work great, but alternatively, especially if you are querying with a SELECT statement, you can assign the MySQL query to a variable, so you can use it later on in the script as well:
PHP Code:
//put query result into variable
$x = mysql_query('Some SQL');
if ($x) {
echo 'The query succeeded.';
//get result data, etc.
$y = mysql_fetch_assoc($x);
echo $y['field_name'];
} else {
echo 'Query failed.';
}