query sql-table and change entities

You should gotten return from SQL first. And then print results. Use $wpdb class for SQL queries.
If you wanna use native SQL queries something like this might helps you

$result = mysql_query("SELECT * FROM table");
$result_array = mysql_fetch_array($result, MYSQL_ASSOC);

But it`s very bad idea. Use $wpdb with preparing.