Jump to content

[SOLVED] MySQL optimization question


cooldude832

Recommended Posts

I have a script that is to search a DB for matching critera.  It works, but I think its running slower than it should be.

 

The first query I run is:

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

that works to get me all matching results.

 

My question is what is stored in that query.  If it matches say 5 (row a,b,c,d,e) and i want to use the results of rows a,b,c later down to populate the matching results.  Can i Do this with out requerying?

Link to comment
Share on other sites

You can do this:

 

$select = "a, b, c";

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

 

So it doesn't include anything that you don't need. You can also use LIMIT to cut it down more.

Link to comment
Share on other sites

mysql_query ($query); contains all of the rows and columns in the query.

 

so if you do * and have 5 rows and 5 columns it will take all of them. If you only query 1 column it will only take that 1 column with 5 rows.

Link to comment
Share on other sites

$query = "SELECT 'ID' FROM ".$table." ".$critera." ".$orderby;

 

$result=mysql_query ($query); //Return ofthe Number of Matching Results

 

Didnt' work

but later on I say:

do
{
          $adid_array[$i] = $row['ID'];
	  $i++;
    }
  while( $row= mysql_fetch_array($result));

 

any idea?

Link to comment
Share on other sites

yeah i think you initially misunderstood me a,b,c are the actual rows i need out of the matching rows a-e so select a,b,c would not work but anyways its a big improvement for now.  It could use a second optimization, but for now and its current function its good.

 

Link to comment
Share on other sites

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.