Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

PHP Help with getting Search Form to search within

chrisj

Bronze Coder
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:
<?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='sub_category_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:
<?php
if (!empty($_POST['search_value'])) {
$search_value = PT_Secure($_POST['subcategory']);
$search_result = $db->rawQuery("SELECT * FROM " . T_VIDEOS . " WHERE title  LIKE '%$search_value%' OR tags LIKE '%$search_value%' OR description LIKE '%$search_value%') AND sub_category LIKE '%$serach_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
 

Attachments

  • VidTable.png
    VidTable.png
    136.4 KB · Views: 1
Last edited:
In my mind this line :-
PHP:
$search_result = $db->rawQuery("SELECT * FROM " . T_VIDEOS . " WHERE title  '%$search_value%' OR tags '%$search_value%' OR description '%$search_value%') AND sub_category = '%$serach_value%' ");

I may be wrong as this query is laid out different to what i would use but i am pretty sure it should be:-
PHP:
$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 ");

Also you should really be using stmt to help keep you data safe 🙂
 
Thank you, but no change. Any additional help is welcomed
How can I have it so it's something like where sub_category = "the name of subcategory" ?
 
Last edited:
Back
Top Bottom