Jump to content

Recommended Posts

I have a search engine I threw together yesterday to query my mysql table and then show $limit results per page of matching results.

since this script is a few hundred lines and unrefined (and my work that I wish to remain private, not public) I will explain its flow.  It seems to be having some load issues and I wanted an opinion on making it faster other than buying a faster server

Here is the script order:

 

1) Take all the user's query and format them into a string called $critera; $query = "SELECT * FROM ".$table." ".$critera." ".$orderby;

 

2) $numresults=mysql_query ($query); //Return of the Number of Matching Results

    $row= mysql_fetch_array ($numresults); //Lets use a fetch array for this

 

3) From the results it forms a dual dimensional array the outer keys are the page numbers so page one is results 1 to result limit page to is from limit+1 to 2limit etc etc.  The inner part of those arrays is the matching result's ID numbers

 

4) Then it does this:

  foreach($page[$currentpage] as $value)//Stops at end of this limit

 

5) In that foreach loop it runs a mysql query:

  $query = mysql_query("SELECT * FROM $table WHERE ID = '$value'") or die(mysql_error());

$result =  mysql_fetch_array($query);

 

6) in the loop it gives out formatted results with echos if else and while functions to interpret the results.

 

For some reason everything loads fine until a point before the ads are created.  Any tips?

 

 

Link to comment
https://forums.phpfreaks.com/topic/52081-optimization-of-a-script-help/
Share on other sites

its not running any more queries than needed unless you know of a way I can retrive all the data in a single query.  hmm actually now that I think about it I run an initial query for the IDs, maybe I can reuse that query's results to get the data I already have.  Any suggestions how to turn :

 

$query = "SELECT * FROM ".$table." ".$critera." ".$orderby; 


$numresults=mysql_query ($query);		//Return ofthe Number of Matching Results
$row= mysql_fetch_array ($numresults);	//Lets use a fetch array for this 
//Puts all the Keys Returned into a Nice Array
do
{
          $adid_array[] = $row['ID'];
    }
  while( $row= mysql_fetch_array($numresults));

into a third level to my two level array containing all my search results?

,but only for $page[$currentpage]  I might be able to do it if i first establish it and then re mysql_fetch_array($numresults) and use if($row['ID']  = $page[$currentpage][$i]) populate $page[$currentpage][$i][$fields];

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.