Jump to content

Why is this slow and cpu intensive as hell?


Rusty3

Recommended Posts

I get 500 over and over from server before getting a successful one. Db is not that big.

 

Any clue greatly appreciated.

 

$query="SELECT * FROM table1 WHERE condition";  

$results=mysql_query($query);
   
   
   while($row = mysql_fetch_array($results, MYSQL_ASSOC))
{
   
          $query2="SELECT * FROM table2 WHERE condition2";  
          $results2=mysql_query($query2);

Errr....  We'll need more code to know for sure, and EXPLAIN results on any queries involved.  Can the two queries be combined using a JOIN?

 

Thanks corbin. So there's nothing wrong with the code...

 

I can't because one depends on the results of the first one. When run alone both are very fast. When together, I get a 500!

 

 

If table1 doesnt have any BLOB fields, ill bet you any money it in the looping queries

 

$query2="SELECT * FROM table2 WHERE condition2"; 
$results2=mysql_query($query2);

 

Do you have to select all from table2? Can you select only the fields you want eg. SELECT name,description FROM table2? And does the table have any BLOB or large fields in it?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.