title: Fetching mysql php table is slow
body: <p>I have a rather large table that takes about 10-20 seconds to <code>fetch</code> depending on the query. That makes website seems slower due to that.</p>
  
  <p>I was thinking of using <code>LIMIT</code> to limit the number of results and using <code>ajax</code> to display the whole table bit by bit.</p>
  
  <p>Right now I am using ajax to display the whole table at once.</p>
  
  <p>I am thinking of doing something like this...</p>
  
  <p>Backend:</p>
  
  <pre><code> $offset = 0;
   $rowsToFetch = 100;
   {
     //Loop
     $query = "SELECT * FROM TABLE_NAME LIMIT $offset, $rowsToFetch"
     $offset = +100;
     $rowsToFetch = +100;
   }
  </code></pre>
  
  <p>Frontend:</p>
  
  <pre><code>Call ajax function that will call the back end part recursively and display part by part until finished.
  </code></pre>
  
  <p>I am sure it's a bit more complicated than that. </p>
  
  <p>Is there a better way to do this? Any ideas how to start? Pitfalls to lookout for? </p>
  
  <p>P.S. I don't want to use pagination. I want to display everything in one page(Benefits: CTRL+F)</p>
  
  <p>Edit: Fetching in the <code>database(command line)</code> takes about 5-7 seconds. But in the website displaying the records take about 10-20 secs. Query takes about 4-5 secs. I timed individual sections of the page to identify that.</p>