$result = mysql_query("SELECT * FROM playersemails",$db);
$sql = "SELECT playersname, email FROM playersemails ORDER BY playersname";
$result = mysql_query( $sql,$db) or die( "query failed: " . mysql_error() );
You don't have to put the query into a separate PHP variable, but it's a really good idea to do so; it can make later debugging much easier. And you should ALWAYS add the or die
just in case.
And you should always avoid using SELECT *
unless you truly will need *ALL* the fields from the table. In this case, since you are only using two fields, you should definitely specify them in the SELECT
. It can make a huge performance difference especially with big tables.