Query the MySQL table once to get all listings for all categories
<pre><code>**categories** mysql table
id|category_name

**listings** mysql table
id|listing_title|category_id
</code></pre>

<p>I want to list all categories on 1 single/same PHP page, with all the listings shown below each category. How can I do this by querying the listings table ONCE. I can do it by making a separate query from within the categories loop, but that would be more than necessary I'm guessing.</p>

<pre>
<code>
//query listings table once
$sql = mysql_query("SELECT * FROM listings", $conn);

//loop through all categories
$sql = mysql_query("SELECT * FROM categories ORDER BY catname", $conn);
while($row= mysql_fetch_array( $sql, MYSQL_ASSOC )){

   //print category name
   print"$row[catname]";

   //print listings of category

}

</pre>

<p></code></p>
