$query=mysql_query(“SELECT * FROM $table_name WHERE name like '%”.$query.“%’ OR company like '%”.$query.“%’ OR address like '%”.$query.“%’ OR email like '%”.$query.“%’ OR phone like '%”.$query.“%’ OR budget like '%”.$query.“%’ OR startdate like '%”.$query.“%’ OR message like '%”.$query.“%'”);
but if i want to run the query for multiple tables and databases, is there any better alternative??
Why do you think that indexing all columns will make them run any faster?
This is such a bad advice, and creating a search engine like stated above is a terrible terrible solution. It will run crappy no matter what, plus it won’t even yield relevant results.
@Blue - If your columns are not indexed then mysql will start at the start of the table and search through every record to find a match, if you columns are indexed, it can jump to any point in the dataset. This will dramatically increase the speed of your queries. See http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html
As far as this being a bad way to implement a search engine, we are in agreement.
@ScallioXTX - That makes sense. Have never used multi database queries before, its an interesting concept
I’m perfectly aware what indexes are and HOW they work. You on the other hand might want to read about inner workings of indexes and how they are used.
To cut the long story short - if the columns from query at the start of the topic would be indexed - it achieves ZERO in terms of speed.
The fact that MySQL would find at what entry the actual data-set is means nothing because index length would be equal to data length, meaning you achieved nothing, the actual time of search with or without index would be more or less the same.
On the other hand, you’d inflate your data storage by double the amount so yeah - indexing everything definitely isn’t the solution to this problem.