Chrisj Posted November 6, 2021 Share Posted November 6, 2021 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 Quote Link to comment https://forums.phpfreaks.com/topic/314176-help-with-getting-search-form-to-search-within/ Share on other sites More sharing options...
Barand Posted November 6, 2021 Share Posted November 6, 2021 Getting your query syntax correct would be a good start. Quote Link to comment https://forums.phpfreaks.com/topic/314176-help-with-getting-search-form-to-search-within/#findComment-1591823 Share on other sites More sharing options...
Chrisj Posted November 6, 2021 Author Share Posted November 6, 2021 Thanks for your reply. I don't see the syntax errors, so I pasted into two seperate syntax checkers and results with 'No issues found'. Please, can you point out my incorrect query syntax? Quote Link to comment https://forums.phpfreaks.com/topic/314176-help-with-getting-search-form-to-search-within/#findComment-1591829 Share on other sites More sharing options...
Barand Posted November 6, 2021 Share Posted November 6, 2021 Getta better checker. When using wildcard (%) characters in a search, you need to use LIKE (not = ) 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. Quote Link to comment https://forums.phpfreaks.com/topic/314176-help-with-getting-search-form-to-search-within/#findComment-1591833 Share on other sites More sharing options...
Chrisj Posted November 6, 2021 Author Share Posted November 6, 2021 (edited) 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 November 6, 2021 by Chrisj Quote Link to comment https://forums.phpfreaks.com/topic/314176-help-with-getting-search-form-to-search-within/#findComment-1591834 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.