Note that there are some explanatory texts on larger screens.

plurals
  1. POExtremely slow search page load (MySQL and PHP)
    text
    copied!<p>I made a simple search box on a page, where a user can type in keywords to look for photos of certain items, using PHP. I'm using an MySQL database. I trim the result and show only 10 to make the loading quicker, but certain set of keywords causes the browser to hang on both IE and Firefox. When this happens on IE, I can see outlines of photos (just the silhouette) beyond the 10 results with an "X" mark at the top right corner, similar to when you load a photo and the photo doesn't exist on a webpage, even though I wrote the code to show only 10 results. The database has over 10,000 entries, and I'm thinking maybe it's trying to display the entire set of photos in the database. Here are some code that I'm using.</p> <p>I'm using the function below to create the query. $keyword is an array of the keywords that the user has typed in.</p> <pre><code>function create_multiword_query($keywords) { // Creates multi-word text search query $q = 'SELECT * FROM catalog WHERE '; $num = 0; foreach($keywords as $val) { // Multi-word search $num++; if ($num == 1) { $q = $q . "name LIKE '%$val%'"; } else { $q = $q . " AND name LIKE '%$val%'";} } $q = $q . ' ORDER BY name'; return $q; //$q = "SELECT * FROM catalog WHERE name LIKE \"%$trimmed%\" ORDER BY name"; } </code></pre> <p>And display the result. MAX_DISPLAY_NUM is 10.</p> <pre><code>$num = 0; while (($row = mysqli_fetch_assoc($r)) &amp;&amp; ($num &lt; MAX_DISPLAY_NUM)) { // add max search result! $num++; print_images($row['img_url'], '/_', '.jpg'); // just prints photos } </code></pre> <p>I'm very much a novice with PHP, but I can't seem to find anything wrong with my code. Maybe the way I wrote these algorithms are not quite right for PHP or MySQL? Can you guys help me out with this? I can post more code as necessary. TIA!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload