The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Logic Question: PHP Search Array
masonh928
post Apr 9 2017, 10:11 PM
Post #1


Serious Coder
*****

Group: Members
Posts: 250
Joined: 17-August 13
From: Indiana
Member No.: 19,570



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!

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Apr 10 2017, 01:53 AM
Post #2


This is My Life
*******

Group: Members
Posts: 1,375
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Apr 10 2017, 06:00 AM
Post #3


.
********

Group: WDG Moderators
Posts: 7,591
Joined: 10-August 06
Member No.: 7



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?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
masonh928
post Apr 10 2017, 02:31 PM
Post #4


Serious Coder
*****

Group: Members
Posts: 250
Joined: 17-August 13
From: Indiana
Member No.: 19,570



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Apr 10 2017, 02:47 PM
Post #5


.
********

Group: WDG Moderators
Posts: 7,591
Joined: 10-August 06
Member No.: 7



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).
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
3 User(s) are reading this topic (3 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 24th June 2017 - 01:54 PM