0

So i'm working with huge MYSQL database of english words. the list has upwards of 180k words. Im trying to run a query, and then compute something using every word in the database. The problem is the database is so big, and it seems to be freezing my browser (Im working locally with MAMP). Is there a way I can do five queries at a time, instead of trying to run through the whole thing, so i can see the results coming in gradually in my browser? Heres the code:

<?php
require 'class.thing.php';
require 'db_config.php';
$result = mysql_query("SELECT * FROM words") or die ("Could not complete query");

while($row = mysql_fetch_array($result))
 {
    $word = $row['word'];
    $compute = $word."thing";
    $finished = new method( $compute );

   if ($finished->successfull()) {
      echo "<br/>";
      echo "worked!";
      echo "<br/>";
   } else {
      echo "uh oh..";
   }

}

?>

** im looking for something like:

 $result = mysql_query("SELECT * FROM words") or die ("Could not complete query LIMIT 0,5");

get results

wait 5 seconds

$result = mysql_query("SELECT * FROM words") or die ("Could not complete query LIMIT 0,5");

get results

etc...

Nick lK
  • 2,647
  • 4
  • 16
  • 14
  • Assuming 1 word per row in your words table, 180k rows is not many rows at all. – Brian Driscoll Jan 09 '14 at 20:28
  • What's the code for the `method` class? – Patrick Q Jan 09 '14 at 20:41
  • Please show your schema for the `words` table. – Marcus Adams Jan 09 '14 at 20:41
  • 1
    possible duplicate of [MySql Data - Best way to implement paging?](http://stackoverflow.com/questions/3799193/mysql-data-best-way-to-implement-paging) – Marcus Adams Jan 09 '14 at 20:43
  • its not about the way it looks, its that i think too many queries are freezing my computer. – Nick lK Jan 09 '14 at 20:46
  • @user1502867 You are only running one query in your original code. If your browser is actually locking up, then it is most likely because you are sending a LOT of data to the browser (and possibly running some javascript on it?). However, the code that you've provided so far does not show where you are sending this data to the client/browser. – Patrick Q Jan 09 '14 at 20:56

1 Answers1

-1

You should take a look at this related question:

What is the best way to paginate results in SQL Server

Note that you can compare words in SQL alphabetically (check whether your settings use case sensitive sorting or not), so you can do something like:

SELECT * FROM words WHERE word <= "ferrous" ORDER BY word

If you're using an auto-incrementing id, you can use that to subdivide as well (it'd probably be easier).

EDIT:

As pointed out below, you can use LIMIT in MySQL.

Example:

SELECT * FROM words LIMIT 0, 1000

(This would display the first 1000 results).

Community
  • 1
  • 1
Cezary Wojcik
  • 21,745
  • 6
  • 36
  • 36