# Help with getting the Search Form to search within subcategory

**URL:** <https://www.phphelp.com/t/help-with-getting-the-search-form-to-search-within-subcategory/34209>\
**Category:** Beginners - Learning PHP\
**Created:** [November 4, 2021, 12:47am UTC](https://www.phphelp.com/t/help-with-getting-the-search-form-to-search-within-subcategory/34209 "2021-11-04T00:47:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisj](https://www.phphelp.com/letter_avatar_proxy/v4/letter/c/f475e1/32.png) [@chrisj](https://www.phphelp.com/u/chrisj)\
**Post date:** [November 4, 2021, 12:47am UTC](https://www.phphelp.com/t/help-with-getting-the-search-form-to-search-within-subcategory/34209/1 "2021-11-04T00:47:43Z")

</div>

Thanks for all the previous help.  
The web video script that I’m modifying successfully filters videos into categories and subcategories. I’ve added this Search Form which appears on subcategory results pages:

```
<?php
if (preg_match('#/?sub__(\d)+\b#',$_SERVER['REQUEST_URI'],$matches)) {
echo "<form action='#' method='GET' id='subcategory'>
<input id='search' name='keywords' type='text' placeholder='Search--SubCategory'>
<input type='submit' value='Search' />
<input type='hidden' id='subcategory' name='subcategory_id' value='{$matches[1]}'>
</form>";
}
?>

```

I’ve also added the following code to the same page in an attempt to get the Search Form to have the functionality of searching just within the currently displayed subcategory page(s) results, for title, description and/or tags(keywords), and display those results:

```
<?php
$data = array('status' => 400);
if (!empty($_POST['search_value'])) {
$search_value = PT_Secure($_POST['subcategory']);
$search_result = $db->rawQuery("SELECT * FROM " . T_VIDEOS . " WHERE (title '%$search_value%' OR tags '%$search_value%' OR description '%$search_value%') AND sub_category = '%$search_value%' ");
if (!empty($search_result)) {
$html = '';
foreach ($search_result as $key => $search) {
$search = PT_GetVideoByID($search, 0, 0, 0);
$html .= "<div class='search-result'><a href='$search->url'>$search->sub_category</a></div>";
}
$data = array('status' => 200, 'html' => $html);
}
}
?>

```

but no success yet. The T\_VIDEOS (videos table) looks like this (attached).  
Any guidance with this is appreciated

 ![VidTable](https://www.phphelp.com/uploads/default/original/2X/1/1183c17cab5de1e37591e0a0c859caf90292de4d.png)
