FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Search Option





jinger89
Alrighty, here's what I'm looking to do: create a search option for my forum where users can say search for the word "cat" and it'll return all posts/comments that include the word cat.

I am currently running the forum using PHP and MySQL where all posts are stored as individual entries in tables that are organized by topic. So I have about 30 tables going right now, one for every topic on my site.

What is the most efficient way to go about creating this search option? And should I be storing post/comment data in a better form? Although, it's a bit hectic for me to reorganize everything, it's not too late at this point.
Diablosblizz
Well, MySQL does have the LIKE command. For example, I am making a video site for a summative at school. I have a search box, if I type in a word such as "fail" it returns all the results that have a title, tags or description related to the word fail. I use this query:

Code:
SELECT * FROM `videos` WHERE `name` LIKE '%$string%'


Basically, the % sign tells MySQL that it's not searching for that EXACT match, yet ones close to it.
kv
jinger89 wrote:

I am currently running the forum using PHP and MySQL where all posts are stored as individual entries in tables that are organized by topic. So I have about 30 tables going right now, one for every topic on my site.


I guess searching itself is not an issue for you (it is a simple sql), but with 30 tables, if they have exactly same structure, you can use UNION. That will be a long query, and even with indexing, union of 30 tables will take lot of time and resource.

jinger89 wrote:

What is the most efficient way to go about creating this search option? And should I be storing post/comment data in a better form? Although, it's a bit hectic for me to reorganize everything, it's not too late at this point.


There is a simple way. Just have one table for forum posts and add an extra column for topic id. Topic can be in one different table (with topic id, topic name, parent topic -- if you want a nested topics structure, etc). If you want to retrieve the posts by topic, query the table with topic id in the where clause. Atmost you may have to join topic table and posts table if you want to retrieve topic name along with each post, but it is still lot better than querying 30 tables.
Related topics
The search option!!!
Search with In the files - Windows XP
Search Script..?
WinTweaX
Cricket on Internet
Firefox...what's the big deal? please enlighten me!
Less posts per page
Gmail?
what kind of music do you like most?
Anyone know how point system works?
How long do requests take?
Add a new useful function
The Veronicas
How to register for a web host??
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.