Click to See Complete Forum and Search --> : need a search script


cloudx575
08-13-2003, 05:57 AM
i'm working on a gaming site, and i need a script to search for games, i think i could do this with MySQL, but i dont want to (if you know of a better way with MySQL, i'm fine with it)... ok i have a directory set aside with only the pages of each game, i need a script that will take out the spaces in the searchfield, and adds .html or whatever file extension i have, and searches the directory for that filename (without spaces and the file extension added, the game searched for will be the filename of that game) all the games will have the same file extension, so no worry there

wow that was confusing, but i kant think of any simpler way to explain it... hope you can understand what i said

Kr|Z
08-13-2003, 06:41 AM
Do you mean something like this?



<form method="post" action="search.php">
<input type="test" name="search">
<input type="submit" value="Search">
</form>

<?php

$folder = "games/"; // Folder with the games
$ext = ".html"; // Extension of the files

$search_string = str_replace(" ", "", $_POST["search"]);

if($search_string) {
$search_string = $folder.$search_string.$ext;
if(file_exists($search_string)) {
print("Game found");
} else {
print("Game not found");
}
}

?>

cloudx575
08-13-2003, 08:33 AM
i need it to go to that html file when found instead of just saying game found

pyro
08-13-2003, 09:01 AM
Try this, instead. Note that the PHP must go before any other content (as you can't set headers after other content has been sent to the page):

<?php

$folder = "games/"; // Folder with the games
$ext = ".html"; // Extension of the files

$search_string = str_replace(" ", "", $_POST["search"]);

if($search_string) {
$search_string = $folder.$search_string.$ext;
if(file_exists($search_string)) {
header("Location:$folder.$search_string.$ext");
} else {
print("Game not found");
}
}

?>

Kr|Z
08-13-2003, 10:39 AM
it would have to be like this

<?php

$folder = "games/"; // Folder with the games
$ext = ".html"; // Extension of the files

$search_string = str_replace(" ", "", $_POST["search"]);

if($search_string) {
$search_string = $folder.$search_string.$ext;
if(file_exists($search_string)) {
header("Location: $search_string");
} else {
print("Game not found");
}
}

?>

pyro
08-13-2003, 10:42 AM
Ah, yes. My bad.... Didn't look at the script to see that you concatenated the values into $search_string...

cloudx575
08-13-2003, 10:45 AM
thanks for your suggestions, i modified it a little,<?php

$folder = "games/"; // Folder with the games
$ext = ".html"; // Extension of the files

$search_string = str_replace(" ", "", $_POST["search"]);
if($search_string) {
$full_search_string = $folder.$search_string.$ext;

if(file_exists($full_search_string)) {
header("Location: $full_search_string");
} else {
print("sorry, but $search_string could not be found");
}
}

?>
but is there a way to open the results in a new window? that would be really usefull

eddieweb12
08-13-2003, 12:06 PM
Hello Pyro! I was talking with you yesterday about a similar script and now I came across this one. I've been looking for almost a week now for a script that will allow be to add a collection of MIDI files to a database or any kind of list, and create a search so one someone types in "Madonna" for instance, it will bring up a window of search results, so that when the visitor clicks on one of the results, the song will play. I tried out this PHP script and it somewhat worked, but it only brought it up if you typed in the exact filename. Anyway, I looked at those sites you told me to (such as HotScripts.com) but I couldn't find any good ones that fit my purpose. Many of them were too lengthy and too hard to understand. But, is there any way that I can take advantage of MySQL Database to make this seach engine? Like I said, I'm a newbie at this but I can learn fast. Thanks very much for your time.

ray12
08-18-2003, 01:29 AM
You might want to take a look at this search engine package:
http://www.wrensoft.com/zoom