Guest Posted September 19, 2020 Share Posted September 19, 2020 hello i need a script that sends data from the searchbar to a search.php and there the entries are displayed with the category someone knows how to write it or has someone an example https://prnt.sc/ujzvuf Quote Link to comment https://forums.phpfreaks.com/topic/311503-help-with-a-search-script/ Share on other sites More sharing options...
requinix Posted September 19, 2020 Share Posted September 19, 2020 You're much more likely to get some help if you can show some initiative on your part first. Like, if you've tried writing the code yourself. Or if you have something partially done to show and don't know how to continue with it. Quote Link to comment https://forums.phpfreaks.com/topic/311503-help-with-a-search-script/#findComment-1581489 Share on other sites More sharing options...
Guest Posted September 19, 2020 Share Posted September 19, 2020 The problem is I don’t have a code because I can’t imagine how to write this. I want to make it so that you can select a category and if you press search then a page comes with cards that own the category Quote Link to comment https://forums.phpfreaks.com/topic/311503-help-with-a-search-script/#findComment-1581499 Share on other sites More sharing options...
mac_gyver Posted September 19, 2020 Share Posted September 19, 2020 doing a search on the www would be of some help. there are countless examples posted on the web showing all the different skills/parts you would need to build this application. designing code involves defining what the user will see and be able to do on each step of a process. this leads to defining what data, if any, you need as an input, what processing you are going to do based on the input data, and what result or output you are going to produce. when a user browses to your category search page, what will they see? a (get method) form with a text input (assuming you don't want just the category menu) and a category (select/option) menu. you can research on the web what the html for those are. next, you would want to dynamically create the option choices by querying the database table where the categories are defined. this will give you the category id (the option values) and the category name (the option labels) data. you would loop over this data to produce the option choices. you would also want to make the search form 'sticky' by populating the text field value with any existing input value and pre-selecting the option that matches any existing selected input value. for safety, you would want to apply htmlentities() to any dynamic data value when you output it onto a web page. this will get you a user interface for the first step in the process. once you get this working, you can move onto the next step of validating the search input(s) (see my reply in your other thread) and safely using them with a prepared select query to find and display any matching data. Quote Link to comment https://forums.phpfreaks.com/topic/311503-help-with-a-search-script/#findComment-1581502 Share on other sites More sharing options...
Guest Posted September 19, 2020 Share Posted September 19, 2020 <?php include 'db2.php'; $model = new Db(); $turistCity = $model->getTouristCity(); $visitingPlace = $model->getVisitingPlaces(); $searchdata = $model->getVisitinPlaceData($_POST['city'], $_POST['place'], $_POST['keyword']); ?> <form action="" method="post" class="serach-form-area"> <div class="row justify-content-center form-wrap"> <div class="col-lg-4 form-cols"> <input type="text" class="form-control" name="keyword" value="<?php echo $_POST['keyword']; ?>" placeholder="what are you looging for?"> </div> <div class="col-lg-3 form-cols"> <div class="default-select" id="default-selects"> <select> <option value="1">Select area</option> <?php foreach($turistCity as $city) { $checked = ($_POST['city'] == $city[city_id])? 'selected' : ''; echo '<option value="'.$city[city_id].'" '.$checked.'>'.$city[city].'</option>'; } ?> </select> </div> </div> <div class="col-lg-3 form-cols"> <div class="default-select" id="default-selects2"> <select> <option value="1">All Category</option> <?php foreach($visitingPlace as $place) { $checked1 = ($_POST['place'] == $place[vid])? 'selected' : ''; echo '<option value="'.$place[vid].'" '.$checked1.'>'.$place[visiting_place].'</option>'; } ?> </select> </div> </div> <div class="col-lg-2 form-cols"> <button type="button" name="search" class="btn btn-info"> <span class="lnr lnr-magnifier"></span> Search </button> </div> </div> <?php $i = 1; if(count($searchdata) > 0 ){ foreach($searchdata as $places) { echo '<div class="card-body">'; echo '<h5 class="card-title">'.$places[city].'</h5>'; echo '<td>'.$places[visiting_place].'</td>'; echo '<td>'.$places[history].'</td>'; echo '</tr>'; $i++; } } else { echo '<td colspan="4">No Search Result Found.</td>'; } ?> </form> https://www.etutorialspoint.com/index.php/45-php-mysql-advanced-search-feature now I have found a script and applied in my code but it does not work when I click search Quote Link to comment https://forums.phpfreaks.com/topic/311503-help-with-a-search-script/#findComment-1581505 Share on other sites More sharing options...
Guest Posted September 20, 2020 Share Posted September 20, 2020 does anyone have an idea why that doesn't work Quote Link to comment https://forums.phpfreaks.com/topic/311503-help-with-a-search-script/#findComment-1581513 Share on other sites More sharing options...
mac_gyver Posted September 20, 2020 Share Posted September 20, 2020 define: "doesn't work"? exactly what did you observe in front of you that leads you to believe that something about the code you have posted doesn't work? did you get a blank page, a bunch of php errors, a database related error, the output about - No Search Result Found, just some of the matching search results, all the database data was displayed, the displayed data was not in the expected order, did the page just refresh, did it appear like the clicking on the button did nothing at all, or a number of other possible symptoms? knowing what symptom you observed, narrows down the problem to just a few things that can be investigated further. next, you should be getting php errors from this ridiculously deficient code you found on the web and are taking a chance with by executing it on your server. this says you don't have php's error related settings setup so that php would help you while learning, developing, or debugging code/query(ies). find the php.ini that php is using and set error_reporting to E_ALL and set display_errors to ON. stop and start your web server to get any changes made to the php.ini to take effect. Quote Link to comment https://forums.phpfreaks.com/topic/311503-help-with-a-search-script/#findComment-1581514 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.