Jump to content

Help with a search script


Guest

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.