site search

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
alexislalas
Forum Commoner
Posts: 44
Joined: Sun Feb 19, 2006 10:09 pm

site search

Post by alexislalas »

hey,

anyone knows where to find or you mind telling me how to build searches for my website.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

If you're looking for pre-made scripts, Hotscripts is always the first place to look. If you're looking at making your own - we'll need some more information.

Is your site content in files or in the database?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
alexislalas
Forum Commoner
Posts: 44
Joined: Sun Feb 19, 2006 10:09 pm

Post by alexislalas »

both, but most of it reads from a database.


whats better to find a script or try to do it by myself?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

If the content is in the database, check out using LIKE syntax, or setting up a FULLTEXT index - both in MySQL.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

alexislalas wrote:both, but most of it reads from a database.


whats better to find a script or try to do it by myself?
If you can find one that does what you want it to, why reinvent the wheel. However, if you love to take on projects just because you 'want to see if I can do this with PHP', then by all means, build one on your own. It really depends on you: your preferences, your abilities, your speed, your knowledge, your patience, your eye color. Well, not really your eye color, but all of the other stuff I said.
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

alexislalas wrote:both, but most of it reads from a database.

whats better to find a script or try to do it by myself?
It always depends on what the user input will be like.

Code: Select all

<?php
$query = "SELECT * FROM database WHERE text like '%$needle%' ORDER BY id DESC";
?>
This will give you all entries containing the keyword $needle. However, if the user is going to search for a specific date, you'll probably have to implement a regex function to ensure that the date is properly formatted.

If you want to display the entries according to relevance, you'll have to sort this selection afterwards - perhaps by checking how many times a single entry contains your keyword (substr_count).

Additionally, if the user is likely to search for a misspelled word, you'll probably have to resort to SOUNDEX.

aerodromoi
Post Reply