Help - Search - Members - Calendar
Full Version: Logic Question: PHP Search Array
HTMLHelp Forums > Programming > Server-side Scripting
masonh928
This seems a little bit elementary, but I would really like to lay this logic out for critique. Often times when people think of a search page, they think of searching a database, but I have a folder with a list of pages that have info on certain poultry breeds. I basically just need a search function that retrieves breed pages. I'm thinking of using AJAX for this just for ease of use, not sure yet... but anyways. I was thinking that since I only have about 40 breeds, I could make an array of all the titles and search based on the array. Any other ideas? Just wanted to see if this logic checks out.

~Thanks,
Mason!

CharlesEF
Since your poultry information is not in a database why involve AJAX? Just make the array and code for client side processing. I mean, you still need javascript for AJAX use.
Christian J
QUOTE(masonh928 @ Apr 10 2017, 05:11 AM) *

since I only have about 40 breeds, I could make an array of all the titles and search based on the array.

That could be done with just PHP, but it requires the user to spell correctly. Why not use an index instead, like a SELECT menu or a list of links?
masonh928
I didn't really think of that. Hmm... I just thought that perhaps an AJAX search was more convenient. I could possibly use something like this I found on PHP.net

CODE

<?php
$dir = "/your_folder_here/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            if($file == $_POST['SEARCHBOX_INPUT']){
                echo('<a href="'.$dir . $file.'">'. $file .'</a>'."\n");
            }
        }
        closedir($dh);
    }
}
?>


Of course, I'd change it a bit.
Christian J
If you're going to use a search script, you might use Ajax to give the user search suggestions (the way e.g. Google does).
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.