S L O W search function

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
redcircle
Forum Commoner
Posts: 43
Joined: Fri Jan 31, 2003 8:47 pm
Location: michigan, usa

S L O W search function

Post by redcircle »

My search function is very slow. What can I do to speed it up.

Code: Select all

function search($search)

{

  $arr = explode(' ',$search);

  for($x=0; $x<sizeof($arr); $x++)

  &#123;

  if($x==0) $search_string = 'fileinfo_a.answer like "%'.$arr&#1111;$x].'%"';

  else

  $search_string .= ' or fileinfo_a.answer like "%'.$arr&#1111;$x].'%"';

  
  &#125;

  for($x=0; $x<sizeof($arr); $x++)

  &#123;

  $search_string_comment .= ' or imagecomments.comments like "%'.$arr&#1111;$x].'%" or imagecomments.name like "%'.$arr&#1111;$x].'%" or imagecomments.email like "%'.$arr&#1111;$x].'%"';

  &#125;
  $query = 'select fileinfo_a.id,fileinfo_a.photo_id from fileinfo_a, access, photofile, imagecomments where ('.$search_string.$search_string_comment.') and photofile.id = imagecomments.photo_id and fileinfo_a.photo_id = photofile.id and photofile.dir_id = access.dir_id and photofile.dir_id = photofile.dir_id  and photofile.dir_id = access.dir_id and access.user_id = "'.$_SESSION&#1111;'squitoid'].'" and access.r = "1" group by photo_id order by id asc';

  $result = $this->query($query);


  echo '<b><i>'.mysql_num_rows($result).'</i></b> Search Results from Search String <b><i>'.$_GET&#1111;'search'].'</i></b><hr>';

  if(!mysql_num_rows($result)) echo 'No results found';

  else echo '<table width="100%">';

  while($myrow=mysql_fetch_array($result))

  &#123;

    echo '<tr><td width="1" valign="top">'."\n";

	echo $this->get_search_icon($myrow&#1111;'photo_id'])."\n";

	echo '</td><td valign="top"></tr>'."\n";

  &#125;

echo '</table>'."\n";


&#125;
Post Reply