title: AJAX MySQL Query Orderby
body: <p>I need to return a database table in a .php script (the AJAX file). I currently have this:</p>
  
  <pre><code>header('Content-type: application/json; charset=UTF-8');
  $gettblstmt = $pdo-&gt;prepare('SELECT *
                               FROM `tbl1` 
                               ORDER BY `ordernum`');
  $gettblstmt-&gt;execute();
  $tbl= $gettblstmt-&gt;fetchAll(PDO::FETCH_ASSOC);
  echo json_encode($tbl);
  </code></pre>
  
  <p>Now, I'm using the <code>$.post</code> function from <code>jQuery</code> to 'run' the PHP script. However, since the result of the AJAX file is an object, the <code>ORDER BY</code> won't be applied.</p>
  
  <p>How could I get the right ordering from MySQL into jQuery?</p>
  
  <pre><code>$.post('someajaxfile.php', function(result) 
  {
      for (var i = 0; i &lt; result.length; i++) 
      {
          $('#someelement').append(result[i] + '&lt;br&gt;');
      }
  });
  </code></pre>