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 3307778
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:26:44+00:00 2026-05-17T21:26:44+00:00

I am doing a query on an mysql database based on typed data sent

  • 0

I am doing a query on an mysql database based on typed data sent from a jquery autocomplete function. It works fine but take several seconds (5-6+) to get the returned suggestions. There are around 200,000 product entries in the database currently which is expected to go to well over a million entries. How can I speed this thing up, as once more entries are added, it stands to reason that the results would likely never show before someone has already typed in the full search query, which does not benefit them at all.

The MySQL tables are:

CREATE TABLE `products` (
  `id` int(12) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL default '',
  `description` text NOT NULL,
  `category` int(12) NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `name` (`name`),
  KEY `category` (`category`)
) ENGINE=MyISAM;

CREATE TABLE `products_pics` (
  `id` int(12) NOT NULL auto_increment,
  `product_id` int(12) NOT NULL default '0',
  `thumb` blob NOT NULL,
  `image` longblob NOT NULL,
  `type` varchar(6) NOT NULL default '',
  PRIMARY KEY  (`id`),
  KEY `product_id` (`product_id`),
) ENGINE=MyISAM;

The PHP code for the search and result return is:

if(isset($_REQUEST['queryString'])) {
 $queryString = addslashes($_REQUEST['queryString']);
 if(strlen($queryString) > 0) {
  $result = mysql_query("SELECT * FROM products WHERE name LIKE '%" . $queryString . "%' ORDER BY name LIMIT 8", $db);
  if(mysql_num_rows($result) > 0){
        while($myrow = mysql_fetch_array($result)){
        $query = mysql_query("SELECT id FROM products_pics WHERE product_id='$myrow[id]' LIMIT 1", $db);
        if(mysql_num_rows($query) > 0){
        echo '<a href=""><img src="/ajax/search_images.php?id=' . $myrow[id] . '" width="55" border="0" alt="" />';
        }
        else {
        echo '<a href=""><img src="/images/items/no-img.jpg" width="55" border="0" alt="" />';
        }
        $name = stripslashes($myrow[name]);
        if(strlen($name) > 35) { 
         $name = substr($name, 0, 35) . "...";
        }             
        echo '<span class="searchheading">' . $name . '</span>';
        $description = stripslashes($myrow[description]);
        if(strlen($description) > 80) { 
         $description = substr($description, 0, 80) . "...";
        }
        echo '<span>' . $description . '</span></a>';
       }
       echo '<span class="seperator"></span>';
   } 
  }
 } 

Thanks again guys, any help is appreciated.

  • 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-17T21:26:45+00:00Added an answer on May 17, 2026 at 9:26 pm

    Doing LIKE %keyword% is very slow. Because you are doing autocomplete you could discard the first %, doing: LIKE keyword%.

    That will speed up your query dramatically.

    Also, try to execute your query in MYSQL like ‘EXPLAIN <>’. This will provide you with info on how MySQL executes your query and where you might optimize.

    Another option might be to use MyISAM’s FULL TEXT SEARCH capability: http://dev.mysql.com/doc/refman/5.1/en/fulltext-search.html

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

Sidebar

Related Questions

Doing odd/even styling with jQuery is pretty easy: $(function() { $(.oddeven tbody tr:odd).addClass(odd); $(.oddeven
I used to use the standard mysql_connect(), mysql_query(), etc statements for doing MySQL stuff
Here is the updated question: the current query is doing something like: $sql1 =
I've recently come across a feature of doing a large query in oracle, where
Is there any way to create the query parameters for doing a GET request
I have a winforms application that is doing the following: on each query: Db
I'm doing a probability calculation. I have a query to calculate the total number
When doing an INSERT with a lot of data, ie: INSERT INTO table (mediumtext_field)
Hey guys, Im doing a series of if statements based on a session variable
I've stored image information in my mysql database like below... id, int(10), PRIMARY KEY

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.