Jump to content

Help with getting Search Form to search within...


Chrisj
 Share

Recommended Posts

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 html 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='subid' name='sub_category_id' value='{$matches[1]}'>
</form>";
}
?>

I've also added the following code to the same html file 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 tags(keywords), and display those results:

<?php
if (!empty($_POST['search_value'])) {
$search_value = PT_Secure($_POST['subid']);
$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).

I need help with a where clause to limit the video data selected to the requested sub category id and display it.

[https://pasteboard.co/6lSH6CKAfFUV.png](https://)

Or, maybe there's a way to have it so it's something like where sub_category = "the name of subcategory" ?

Any guidance with this is appreciated

 

Link to comment
Share on other sites

Getta better checker.

When using wildcard (%) characters in a search, you need to use LIKE (not = )

image.png.e207a6f427da13e26eb32235abc07a17.png

Also, I would have thought the subcategory value in your search would be the same one that was selected to get you to that page, not the same as the other search values.

Although not an error, you should be using prepared queries and not put variables in the query string.

Link to comment
Share on other sites

Many thanks again.

I have corrected the LIKE and retried without success.

Regarding "the subcategory value in your search would be the same one that was selected to get you to that page",
when the web script filters results to a category, the url, for example, looks like this:

....com/videos/category/1?page_id=1

and from there when a subcategory is selected, for example, the url looks like this:

....com/videos/category/1/sub__536

so, I tried this:

AND sub_category LIKE '%$subid%'

 

Otherwise, it would be great to have it so it's something like: AND sub_category LIKE "the name of the currently displayed page's subcategory"  or 
AND sub_category LIKE "the currently displayed pages's subcategory id"

I look forward to any additional clarification/guidance

Edited by Chrisj
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.