Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6087799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:54:41+00:00 2026-05-23T11:54:41+00:00

I made a simple search box on a page, where a user can type

  • 0

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.

I’m using the function below to create the query. $keyword is an array of the keywords that the user has typed in.

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";
}

And display the result. MAX_DISPLAY_NUM is 10.

$num = 0;
while (($row = mysqli_fetch_assoc($r)) && ($num  < MAX_DISPLAY_NUM)) {  // add max search result!
    $num++;
    print_images($row['img_url'], '/_', '.jpg');    // just prints photos               
}

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!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:54:42+00:00Added an answer on May 23, 2026 at 11:54 am

    Don’t limit your search results in PHP, limit them in the SQL query with the LIMIT keyword.

    As in:

    select * form yourtable where ... order by ... limit 10;
    

    BTW, those LIKE '%something%' can be expensive. Maybe you should look at Full text indexing and searching.

    If you want to show a More... link or something like that, one way of doing it would be to limit your query to 11 and only show the first ten.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've made a simple http server using Twisted, which sends the Content-Type: multipart/x-mixed-replace header.
I made a simple ajax live search in PHP and javascript. I used standard
I have been playing around a bit with a fairly simple, home-made search engine,
On Windows, testing different OSes is made simple using VMs. Is there a simple
We made a simple application and using GoogleAppEngineLauncher (GAEL) ran that locally. Then we
I have made my own file type (.ddd) and I made a simple program
I made a little search-function with javascript to look for a string in a
I have a problem. I made a simple search engine which searches by brand
I made a simple counter, but it increments by 2 instead of 1. $handle
I have made a simple test application for the issue, two winforms each containing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.