PHP MySQL grouping and ordering I have a tv show I created a MySQL database for. I am trying to get my code to group and order correctly the seasons and episodes within their respective season.

Current Code

if (!($result = mysql_query("SELECT season_num, sub_season_num, esp_num, title, descrip FROM season ORDER BY season_num, sub_season_num", $link))) showerror();
$season_one = 1;
$season_two = 2;
echo "Season 1&lt;br&gt;";
while ($row = mysql_fetch_array($result))
{
if(season_num !== $season_one){
echo "Episode {$row["esp_num"]}&lt;br&gt;";
echo "Title {$row["title"]}&lt;br&gt;";
echo "Description {$row["descrip"]}&lt;br&gt;";
}}
echo "Season 2&lt;br&gt;";
while ($row = mysql_fetch_array($result))
{
if(season_num !== $season_two){
echo "Episode {$row["esp_num"]}&lt;br&gt;";
echo "Title {$row["title"]}&lt;br&gt;";
echo "Description {$row["descrip"]}&lt;br&gt;";
}}
?&gt;


Example
Season 1
Eps 1
Eps 2
Eps 3
Season 2
Eps 1
Eps 2
Ect..

Any code help would be greatly appreciated.
You didn't need to hard-code season values like 1 and 2. Just use the nicely sorted repeating values from the rows and detect when the value changes from one row to the next.  With such a generic test, as shown below, you can use one loop and avoid repeated code.

Also note that you seemed to be using the wrong operator, !== the not-identical operator to do an equality test.

if (!($result = mysql_query("SELECT season_num, sub_season_num, esp_num, title, descrip FROM season ORDER BY season_num, sub_season_num", $link))) showerror();
$previous_season = 0; // start with nonsense value to force a heading
while ($row = mysql_fetch_array($result))
{
    $season = $row["season_num"]
    // Ignoring subseason in this version.
    // Decide whether to match both season and sub_season and
    // print both in a new header, complicating this `if` statement
    // OR have a separate, similar `if` statement and separate (sub)header
    // for subseasons. In the latter case, be sure to
    // reset previous_subseason to a nonsense value whenever season changes
    // Otherwise, a subseason header will be missing if a season happens to end
    // on the same subseason number (like 1) that the next season begins with.
    if ($season != $previous_season) {
        $echo "Season $season&lt;br&gt;";
        $previous_season = $season;
    }
    echo "Episode {$row["esp_num"]}&lt;br&gt;";
    echo "Title {$row["title"]}&lt;br&gt;";
    echo "Description {$row["descrip"]}&lt;br&gt;";
}