/    Sign up×
Community /Pin to ProfileBookmark

Pointers For Making A DB Search Script

I’m currently making a script that searches a table for the term(s) a user entered. My current idea is outlined below but I’m not sure it’s very efficient:

1) preg_replace out any words under 3 characters long and some common words like ‘they’re’ etc. unless they’re preceeded by a ‘+’.

2) Preg’ < and > to &lt; and &gt; and escape the characters that need escaping. Strip off punctuation.

3) If $term has ” at the start and end, Preg off ^ and “$ and define $search0 as $term else define $words = explode(” “, $term); and define $search1 as ‘%$term%’.

4) $to_echo = returned rows from $search0

5) $to_echo .= returned rows from $search1

6) if($words) { $words2 = “%”; foreach($words as $w) { $words2 .= $w . “%” } }

7) $to_echo .= returned rows from a mysql_query() SELECTing $words2

8) echo($to_echo);

I hope that made any sense – I would obviously add some error checking too – “No terms entered”, “No results found” etc.

Basically, what I need is some feedback on whether there is a more efficient way of doing it and if I’ve missed anything.

Thanks & Regards, Jonnie

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@sciguyryanSep 19.2004 — Well, I found a good tutorial on the matter, it may help:

http://www.zend.com/zend/tut/tutorial-ferrara1.php



RyanJ
Copy linkTweet thisAlerts:
@JavaHead_JonnieauthorSep 19.2004 — Sweet, thanks for the linky!
Copy linkTweet thisAlerts:
@sciguyryanSep 19.2004 — [i]Originally posted by JavaHead Jonnie [/i]

[B]Sweet, thanks for the linky! [/B][/QUOTE]



No problem.


RyanJ
×

Success!

Help @JavaHead_Jonnie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...