Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Server-side Scripting _ Logic Question: PHP Search Array

Posted by: masonh928 Apr 9 2017, 10:11 PM

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!


Posted by: CharlesEF Apr 10 2017, 01:53 AM

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.

Posted by: Christian J Apr 10 2017, 06:00 AM

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?

Posted by: masonh928 Apr 10 2017, 02:31 PM

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.

Posted by: Christian J Apr 10 2017, 02:47 PM

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).

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)