title: Sorting nested While() Loops
body: <p>I'm able to sort the second tier while loop for obvious reasons but I cannot get the first one to sort. I know its cause the "for" loop is incrementing. What I want is alphabetically sort first while loop then the second ASC...any suggestions? Here's my code </p>
  
  <pre><code>function get_content() {
      $sql1 = "SELECT * FROM category";
      $res1 = mysql_query($sql1) or die(mysql_error());
      $total = mysql_num_rows($res1) or die(mysql_error());
  
      for($a = 1; $a &lt;= $total; $a++) {
          $sql = "SELECT * FROM weblinks INNER JOIN category ON category_weblinks = id_category WHERE id_category = '$a' AND status_weblinks = 'checked' ORDER BY title_weblinks ASC";
          $res = mysql_query($sql) or die(mysql_error());
          while($row = mysql_fetch_assoc($res)) {
              echo "\n\n\n" . '&lt;div class="post"&gt;' . "\n";
              echo '&lt;div class="title"&gt;' . "\n";
              echo '&lt;h2&gt;&lt;a name="' . $row['shortcut_category'] . '"&gt;' . $row['title_category'] . '&lt;/a&gt;&lt;/h2&gt;' . "\n";
              echo '&lt;p&gt;&lt;small&gt;Posted by Joe &lt;a href="mailto:"&gt; email&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;';
              echo '&lt;/div&gt;' . "\n";
              echo '&lt;div class="entry"&gt;' . "\n";
              $res = mysql_query($sql) or die(mysql_error());
              while($row = mysql_fetch_assoc($res)) {
                  echo "\n" . '&lt;p&gt;&lt;b&gt;' .$row['title_weblinks']. '&lt;/b&gt;&lt;br&gt;' . "\n";
                  echo $row['description_weblinks']. '&lt;br&gt;' . "\n";
                  echo 'Link: &lt;a href="' .$row['link_weblinks']. '" target="_blank"&gt;' .$row['link_weblinks']. '&lt;/a&gt;&lt;br&gt;' . "\n";
                  echo 'User: ' .$row['username_weblinks']. ' | Password: ' .$row['password_weblinks']. '&lt;/p&gt;' . "\n";
              }
              echo '&lt;p class="links"&gt; &lt;a href="#" class="more"&gt;Back to Top&lt;/a&gt;&lt;/p&gt;';
              echo '&lt;/div&gt;';
              echo '&lt;/div&gt;';
          }
      }
  }
  </code></pre>