Here is my table:
// tags
+----+-----------+-----------------------------------------+
| id | name | description |
+----+-----------+-----------------------------------------+
| 1 | function | some explanations about function .. |
| 2 | array | some explanations about arrqay .. |
| 3 | HTML | some explanations about HTML .. |
+----+-----------+-----------------------------------------+
Now I'm trying to make a auto-complete box which suggests some tags. Here is my current code:
// current value of the input which has been sent by an ajax request
$input_value = $_POST['q'];
// DB connection is here
$stmt = $db->prepare("SELECT name, description
FROM tags
WHERE name LIKE CONCAT('%', ?, '%') OR description LIKE CONCAT('%', ?, '%')
LIMIT 6");
$stmt->execute(array($input_value,input_value));
But my query is getting slow. For example sometimes it takes 1 sec to return results. Because my table is getting bigger gradually, So I need to improve my query. Is there any idea?
Noted that I have two indexes on name
and description
columns separately.