I'm new to programming in php. I was wondering how I could create a text search box engine for my website that would pull a list of types of dogs from a CSV file. So, let's say a user enters into the text box, Poodle, the output in my web browser would be all the poodles listed in the column 'Category' in my csv file. I don't want to use SQL for this. How would I create the form, so the user could search by category and output the images of these dogs to my web browser? So far, I have the following code written, but I'm not sure if I'm on the right track and how I would create the search engine?
$dogcategories = array();
$fp = fopen('dogcategories.csv', 'r');
$headers = fgetcsv($fp);
while ($x = fgetcsv($fp)) {
$dog[] = array_combine($headers, $x);
}
fclose($fp);
foreach($allDogcategories = array();
foreach($dogcategories as $row) {
$allDogcategories[] = $row['Category'];
}
$allDogcategories = array_unique($allDogcategories);
foreach($allDogcategories as $key => $category) {
echo '<li><a href="'.$_SERVER['PHP_SELF'].'? category = '.$key.'">'.$category.'</a></li>';
}
if (isset($_GET['category']) && array_key_exists($_GET['category'], $allDogcategories)) {
$SelectedDogCatagory = $_GET['category'];
}
foreach($dogcategories as $array) {
if (isset($SelectedDogCatagory) && $allDogcategories[$SelectedDogCategory] !== $array['Category']) {
continue;
}
echo ' < a href = "'.$array['Img'].'" > < img src = "'.$array['IMG jpg'].'"
width = "140"
height = "140"
alt = "'.$array['ALT'].'"
longdesc = "'.$array['IMG link'].'" / > < /a> < h4 > '.$array['Name of Dog '].' < /h4>';
}
echo '<form method="GET" action="'.$_SERVER['PHP_SELF'].'">';
echo '<h1>Search Categories</h1>';
echo '<BR>';
echo '<input type="text" name="search">'.' ';
echo '<input type="submit" name="searchButton" value="Search">';
echo '<BR>';
echo '</form>';