Need help with my PHP search script!!??

D

DAZZ

Guest
Hi, I have a search script in PHP which searches a MYSQL DB table for websites, and what's on them. The current setup is:

'number' the number of the website
'url' the url of the website
'contains' this is where the search script searches in, and its whats on the website.

The searching works great, but I need something to be added to it....

For example, I have the the sites http://www.yahoo.com/ and http://www.php.net/ in the databas, setup like so...

'1' 'http://www.yahoo.com/ 'search, good search engine, the.greatest.search, good.place'

'2' 'http://www.php.com/ 'php, php makers, great.info'

As you see, each 'keyword' is seporated by a comma ',' And when someone searches for, let's say "good"....this would show up...

SITE NUMBER '1'
URL: http://www.yahoo.com
Contains: search, good search engine, the.greatest.search, good.place

it displays that, because the word good is in the contains field of this website

But what im wanting to do is to make it so when someone searches for "good" this will come up...

SITE NUMBER '1'
URL: http://www.yahoo.com/
Contains: good search engine, good.place

What happens is, it takes away everything that doesnt contain "good" in it, it takes away 'search, the.greatest.search'

I know it would be possible, because of the commas ',' just do something with them to make this possible..

Im really new to php, so i dont know anything....

PLease try to help me out, this is important, thank you!!!

If you don't understand something, please tell me, I really need this working!!

Thanks
 
I'd use explode() to split the string, search each piece for "good" and then reassemble the ones containing "good". I think that's the easiest way. :)
 
im really new to PHP, and i really wouldnt know where to start with that, could i just send you my entire PHP search script, and u can look it over??

pleeease
 
Try this before printing $replaced. (Untested code)

PHP:
$keyarr = explode($replaced, ",");
$replaced = "";
for(int $i=0;$i<sizeof($keyarr);$i++){
	if(stristr($keyarr[$i], $search)){
		$replaced .= $keyarr[$i] . ",";
	}
}
// Remove trailing comma
$replaced = substr($replaced, 0, strlen($replaced) - 2));
 
i get...

Parse error: parse error, unexpected T_VARIABLE, expecting ';' in /www/www2/123/search.php on line 73
:huh: :huh:
 
show us line 73, or you can just check to see if there is a ; at the end of the line or the line before it.
 
Umm, my bad. Skip "int ".

PHP:
$keyarr = explode($replaced, ",");
$replaced = "";
for($i=0;$i<sizeof($keyarr);$i++){
    if(stristr($keyarr[$i], $search)){
        $replaced .= $keyarr[$i] . ",";
    }
}
// Remove trailing comma
$replaced = substr($replaced, 0, strlen($replaced) - 2));

I told you I hadn't tested the code! :p (still haven't)
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back