PHP - Moved: Filter Inappropriate Search Results
This topic has been blindfolded and driven across the boarder to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=344623.0 (That was a pun, not a typo.) Similar Tutorialshi, I have a search page with a checkbox $departuk that returns the value "true" if checked. I want to return search results if this returns true and the flag 'Y' is available if ($departuk == "true"){ if ($data[$i]['departuk'] == 'Y'){ $result = $obj->result; } else{ echo "do some thing else"; } else{ echo"there was a problem"; } any pointers / advice is appreciated thanks hello. i have a search box that will display some results. I also have a drop down list with values "1" and "2". the values for each results are stored into database in a "req" field. Code: [Select] <select name="req" id="req"> <option value="1">yes</option> <option value="2">no</option> </select> $sql = 'SELECT * FROM topic WHERE (Title LIKE '."'%$search1%') AND req='1' what am i missing. thanks I'm ready for the next step on my site, which is learning how to filter results down with a second search. The scenario is: A viewer searches for a plant by 4 variables to describe the leaf. After submit, they go to the results page, with 200 paginated results. (This is where I've gotten to) Now, on that same page, they choose to further narrow their results by searching those 200 results for plants that have purple flowers. Maybe they get 40 results and can use another variable to narrow further - and so on. What's the best way to set this up? I've been looking into temporary tables, but it seems to be a challenge because the table deletes the moment they leave that page or close the connection? Sessions seem like another possibility, but I read there's security issues. What's the best way to set this up? Just re-query the database with the entire set of variables from both the first and second searches? is it quicker to build some type of permanent table with a timestamp that I can use to delete it after the user has gone away? This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=359102.0 Hey guys I am having a bit of a hard time understanding how I can fetch data from my SQL table using AJAX and jQuery, I am sorry if this isn't the right place to post this however I usually get great support here.
I am trying to recreate this filter on the right of the page: http://www.autotrade...arch/used/cars/
So basically I have this code to display the whole MySQL table into a list:
<?php while($row = $results->fetch(PDO::FETCH_ASSOC)) { echo ' <div class="listing-container"> <h3 class="model-listing-title clearfix">'.$row["Make"].' '.$row["Model"].' '.$row["Variant"].'</h3> <h3 class="price-listing">£'.number_format($row['Price']).'</h3> </div> <div class="listing-container-spec"> <img src="'.(explode(',', $row["PictureRefs"])[0]).'" class="stock-img-finder"/> <div class="ul-listing-container"> <ul class="overwrite-btstrp-ul"> <li class="diesel-svg list-svg">'.$row["FuelType"].'</li> <li class="saloon-svg list-svg">'.$row["Bodytype"].'</li> <li class="gear-svg list-svg">'.$row["Transmission"].'</li> <li class="color-svg list-svg">'.$row["Colour"].'</li> </ul> </div> <ul class="overwrite-btstrp-ul other-specs-ul h4-style"> <li>Mileage: '.number_format($row["Mileage"]).'</li> <li>Engine size: '.$row["EngineSize"].'cc</li> </ul> <button href="#" class="btn h4-style checked-btn hover-listing-btn"><span class="glyphicon glyphicon-ok"></span> History checked </button> <button href="#" class="btn h4-style more-details-btn hover-listing-btn tst-mre-btn"><span class="glyphicon glyphicon-list"></span> More details </button> <button href="#" class="btn h4-style test-drive-btn hover-listing-btn tst-mre-btn"><span class="test-drive-glyph"></span> Test drive </button> <h4 class="h4-style listing-photos-count"><span class="glyphicon glyphicon-camera"></span> 5 More photos</h4> </div> '; } ?>As you can see I am using a while loop to display the whole contents of the table into lists, this includes vehicle data. I also have this bit of HTML that I will be using as a form to filter the results: <form class="car-finder-container dflt-container"> <h2 class="h2-finder">Car finder</h2> <ul class="toggle-view"> <li class="li-toggle"> <h4 class="h4-finder-toggle">Make<span class="glyphicon glyphicon-plus glyph-plus-toggle"></span></h4> <div class="panel"> <select class="form-control select-box"> <option value="make-any">Make (Any)</option> <option value="two">Two</option> <option value="three">Three</option> <option value="four">Four</option> <option value="five">Five</option> </select> <select class="form-control last-select select-box"> <option value="model-any">Model (Any)</option> <option value="two">Two</option> <option value="three">Three</option> <option value="four">Four</option> <option value="five">Five</option> </select> </div> </li> <li class="li-toggle"> <h4 class="h4-finder-toggle">Body type<span class="glyphicon glyphicon-plus glyph-plus-toggle"></span></h4> <div class="panel"> <input id="four-by-four-checkbox" class="float-checkbox" type="checkbox"/> <label for="four-by-four-checkbox" class="label-checkbox">4x4</label> <input id="convertible-checkbox" class="float-checkbox" type="checkbox"/> <label for="convertible-checkbox" class="label-checkbox">Convertible</label> <input id="coupe-checkbox" class="float-checkbox" type="checkbox"/> <label for="coupe-checkbox" class="label-checkbox">Coupe</label> </div> </li> <li class="li-toggle"> <h4 class="h4-finder-toggle">Transmission<span class="glyphicon glyphicon-plus glyph-plus-toggle"></span></h4> <div class="panel"> <input id="automatic-checkbox" class="float-checkbox" type="checkbox"/> <label for="automatic-checkbox" class="label-checkbox">Automatic</label> <input id="manual-checkbox" class="float-checkbox" type="checkbox"/> <label for="manual-checkbox" class="label-checkbox">Manual</label> <input id="semi-auto-checkbox" class="float-checkbox" type="checkbox"/> <label for="semi-auto-checkbox" class="label-checkbox">Semi automatic</label> </div> </li> </ul> <button href="#" class="btn btn-block car-search-button btn-lg btn-success"><span class="glyphicon car-search-g glyphicon-search"></span> Search cars </button> <h4 class="h4-finder"><a href="#">Try our Smart Search </a><span class="glyphicon info-car-search-g glyphicon-info-sign"></span></h4> </form>I have noticed that JS and Ajax give a great user experience when it comes to filtering search results, in this HTML template I have added some select elements and check boxes and I am now really stuck. Does anybody know how I can make exceptions to what SQL results are returned to the front end or know of any tutorials? Thanks My db is called localDB, and the table in that db is called MonthlySales. I want to display the table in a table in php. But to be able to filter the table by the column year, so if 2000 is selected only the values with 2000 are shown. Is there also a better way to populate the drop down menu? My script looks like: Code: [Select] <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post' name='form_filter' > <select name="value"> <option value="all">All</option> <option value="2000">2000</option> <option value="2001">2001</option> </select> <input type='submit' value = 'Filter'> </form> <?php $link = mysql_connect('localhost', 'root', 'root'); if (!$link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db('localDB', $link); if (!$db_selected) { die (mysql_error()); } // process form when posted if(isset($_POST['value'])) { if($_POST['value'] == '2000') { $query = "SELECT * FROM MonthlySales WHERE Year='2000'"; } elseif($_POST['value'] == '2001') { $query = "SELECT * FROM MonthlySales WHERE Year='2001'"; } else { $query = "SELECT * FROM MonthlySales"; } $sql = mysql_query($query); while ($row = mysql_fetch_array($query)) { $Id = $row["Id"]; $ProductCode = $row["ProductCode"]; $Month = $row["Month"]; $Year = $row["Year"]; $SalesVolume = $row["SalesVolume"]; echo "<tr>"; echo "<td>" . $row['Id'] . "</td>"; echo "<td>" . $row['ProductCode'] . "</td>"; echo "<td>" . $row['Month'] . "</td>"; echo "<td>" . $row['Year'] . "</td>"; echo "<td>" . $row['SalesVoulme'] . "</td>"; echo "</tr>"; } mysql_close($con); } ?> Here is my HTML code: Code: [Select] <html> <head> <title>Simple Search Form</title> </head> <body> <form name="searchform" method="get" action="/search.php"> Select Gender: <select name="gender"> <option value="Male">Male</option> <option value="Female">Female</option> </select> Select City: <select name="gender"> <option value="all">All Cities</option> <option value="newyork">New York</option> <option value="toronto">Toronto</option> <option value="london">London</option> <option value="paris">Paris</option> </select> <form> </body> </html> Here is my PHP code: <?php // get the data from the search form # get the gender (male or female) $gender = $_GET['gender']; # get the city $city = $_GET['city']; // connect to mysql and select db mysql_connect('localhost', 'root', 'pass') or die(mysql_error()); mysql_select_db($test_db); // send query $query = mysql_query("SELECT * FROM `visitors_location` WHERE gender='$gender' AND city='$city'"); $count = mysql_num_rows($query); // display data while ( $show = mysql_fetch_assoc($query) ) { echo $gender . " " . $city; } ?> My script basically shows # of males or females in a specific city. How can I show all males in all cities? In other words, let's say I want to show # of Females from all those 4 cities combined. I don't know how to do that. Can someone please help me? Hi there I have a DB of design work all the work is categorise as Brand Identity, print or online Some are a mix so project 1 is categorised as brand identity and online Project 2 is print and online Im trying to filter my results by using checkbox so when brand identity and online are checked and the filter button is clicked there val is sent to the display page, i am passing the val ok as i get this in the url bar (index1.php?cid=bi&cid2=online) but is not displaying only entry's with cat brand identity and online. its not displaying any thing but error msg In my DB I have 3 columns cid, cid1, cid2. cid= bi cid1= print cid2= online I have 2 problems if anyone can help please. 1, I get no results on the display page(index1.php) when no filter is slected ie show all i think this part needs a IF empty run this query if not empty ie filters have been passed to the page run this query ####################### i get this error There was a problem with the SQL query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '''' at line 1 ####################### 2, I cant get the filters to filter so no display again (cant seam to get the sql select command to work right and fetch the results i need i just get the above error Thank you for any help im still noobish but getting there slowly very slowly lol Anymore info needed let me know nav code (iv used method get to see what is being passed to index1.php the display page) Code: [Select] <form id="form1" name="filter" method="get" action="index1.php"> <ul> <li><a href="/work/"title="Show All"<?php if ($_SESSION['section'] == 'all') { echo "class=\"selected\""; }?>>Show All</a></li> <li>Brand Identity <input name="cid" type="checkbox" value="bi" /></li> <li> Print <input name="cid1" type="checkbox" value="print" /></li> <li>Online<input name="cid2" type="checkbox" value="online" /></li> </ul> <input type="submit" name="" id="filter" value="Filter" /> </form> display page code Code: [Select] <?php error_reporting(E_ALL); include ("includes/db_config.php"); mysql_connect($db_hostname,$db_username,$db_password); @mysql_select_db($db_database) or die( "Unable to select database"); $cid= $_GET['cid']; $cid1= $_GET['cid1']; $cid2 = $_GET['cid2']; $query="SELECT * from `$db_table` WHERE `cid`='".$cid."' or `cid1`='".$cid1."' or `cid2`'".$cid2."'"; $result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error()); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 4; while($row = mysql_fetch_array($result)) { extract($row); if($i == 0) echo "<tr>"; if($pro_name != "" && $pro_name != null) echo "<td class=\"results\"><a href=\"details.php?id=$row[id]\"><img src=\"/work/thumbnails/$row[thumbnail]\" alt=\"$row[thumbnail]\" height=\"155\" width=\"155\" /><br><h2>$row[pro_name]<br></a></h2><p>$row[short_details]</p></td>"; if(++$i == $max_columns) { echo "</tr>"; $i=0; } } } if($i > 0){ for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; echo '</tr>';} ?></table></td> </tr> </table> Hi, I'm currently learning PHP through tutorials and I am working on a webpage that filters statistics (crime records) from an SQL table and filters them by an option of years that the user has picked from a dropdown box. $desiredyear = $_POST['year'] is the year picked from the drop down box on a different page. I did not encounter any problems simply displaying the entire table until I tried to filter the crimes by year. I keep getting this error message. Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given in C:\RDEUsers\NET\400792\1.php on line 40 Here is the error line. Code: [Select] while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) And here is my code so far Code: [Select] <?php $server = 'SQL2008'; $connectionInfo = array( "Database"=>"rde_400792"); $conn = sqlsrv_connect($server,$connectionInfo); $desiredyear = $_POST['year']; $describeQuery='select year, force, homicide from crime where year = $desiredyear '; $results = sqlsrv_query($conn, $describeQuery); echo '<table border="1" BORDERCOLOR=Black>'; echo '<tr><th bgcolor = "LightBlue">Year</th><th bgcolor = "LightBlue" >Force</th><th bgcolor = "LightBlue">Homicide</th></tr>'; while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) { echo '<tr>'; echo '<td >' .$row['year'].'</td>'; echo '<td>' .$row['force'].'</td>'; echo '<td>' .$row['homicide'].'</td>'; echo '</tr>'; } echo '</table>'; sqlsrv_close($conn); Please can somebody help me fix this? It's driving me mad and I've exhausted my limited knowledge on the subject. I just don't understand what I'm doing wrong. I am in the middle of a project on my own website and want to add a filter on it, the results are displayed in a HTML table and are pulled in from a mysql database using php and want to add a text filter on the site. I want the filter to work by clicking on a status text link such as open, pending or closed and it filters the results that match that on the same page for that relevant text value. I was not sure if it's more a php question or if can be done with ajax/javascript Hi there i have 3 tables joined together and am outputting the results ok. Heres what the results look like: Fleet Name: Home One Detected: No Ship Name: Slave 1 Bobafett Hull: 3 / 2 Fleet Name: Home Two Detected: Yes Ship Name: Imperial Star Destroyer Hull: 2 / 4 Fleet Name: Home Two Detected: Yes Ship Name: Executer Hull: 10 / 10 The 3 tables join together by the following: Planet = parsed url parameter Fleets = fleets on the current planet Ships = current ships in the fleets Its all working fine except for one thing, the Fleet Name is repeated for each occurance of a ship. I want to make it so that Fleet Name only occurs once for each fleet so it would look something like: Fleet Name: Home One Detected: No Ship Name: Slave 1 Bobafett Hull: 3 / 2 Fleet Name: Home Two Ship Name: Imperial Star Destroyer Detected: Yes Hull: 2 / 4 Ship Name: Executer Detected: Yes Hull: 10 / 10 Is this possible??? Heres the code in full: Code: [Select] <?php require_once('Connections/swb.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $colname_Planet = "-1"; if (isset($_GET['recordID'])) { $colname_Planet = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']); } mysql_select_db($database_swb, $swb); $query_Planet = sprintf("SELECT * FROM planet WHERE PlanetName = %s", GetSQLValueString($colname_Planet, "text")); $Planet = mysql_query($query_Planet, $swb) or die(mysql_error()); $row_Planet = mysql_fetch_assoc($Planet); $totalRows_Planet = mysql_num_rows($Planet); $colname_Fleet = "-1"; if (isset($_GET['recordID'])) { $colname_Fleet = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']); } mysql_select_db($database_swb, $swb); $query_Fleet = sprintf("SELECT p.PlanetName, p.PlayerName, f.FleetName, f.Detected, s.ShipName, s.HealthA, s.HealthB FROM Planet p LEFT JOIN Fleet f ON (p.PlanetName = f.PlanetName) LEFT JOIN Ships s ON (f.FleetName = s.FleetName) WHERE p.PlanetName = '$colname_Planet'"); $Fleet = mysql_query($query_Fleet, $swb) or die(mysql_error()); $row_Fleet = mysql_fetch_assoc($Fleet); $totalRows_Fleet = mysql_num_rows($Fleet); ?> <head> <title>Untitled Document</title> <style type="text/css"> <!-- body { background-color: #FFFFFF; } --> </style></head> <body> <table width="60%" border="0"> <tr> <td width="10%">Planet:</td> <td width="14%"><?php echo $row_Planet['PlanetName']; ?></td> <td width="7%" rowspan="8"> </td> <td colspan="2" rowspan="8"> <?php while ($row_Fleet = mysql_fetch_assoc($Fleet)) { echo '<table width="400" border="0"><tr><td width="200">'; echo 'Fleet Name: '; echo'</td><td>'; echo $row_Fleet['FleetName']; echo'</td></tr><tr><td>'; echo 'Detected: '; echo'</td><td>'; if ($row_Fleet['Detected'] == '1'){ echo 'Yes';} else echo 'No'; echo'</td></tr><tr><td>'; echo 'Ship Name: '; echo'</td>'; echo'<td>'; echo $row_Fleet['ShipName']; echo'</td></tr><tr><td>'; echo 'Hull: '; echo'</td><td>'; echo $row_Fleet['HealthA']; echo ' / '; echo $row_Fleet['HealthB']; echo '</td></tr><tr><td></td></tr>'; echo'</table>'; } ?> <tr> <td>Faction:</td> <td><?php echo $row_Planet['PlayerName']; ?></td> </tr> <tr> <td>Infastructure</td> <td> </td> </tr> <tr> <td>Class 1: </td> <td><?php echo $row_Planet['Class1']; ?></td> <tr> <td>Class 2: </td> <td><?php echo $row_Planet['Class2']; ?></td> </tr> <tr> <td>Class 3: </td> <td><?php echo $row_Planet['Class3']; ?></td> </tr> <tr> <td>Class 4: </td> <td><?php echo $row_Planet['Class4']; ?></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> <a href="index.php target="main2.php"">Back</a></td> <td> </td> <td> </td> <td width="43%"> </td> <td width="26%"> </td> </tr> </table> </body> </html> <?php mysql_free_result($Planet); mysql_free_result($Fleet); ?> Thanks I have some text boxes for searching the students in database also i have a drop down box for selecting student with balance amount to be paid tell me how to filter or search the list of stuents Code: [Select] <select> <option value="">All </option> <option value="">Unpaid </option> <option value="">Paid </option> </select> Hello, I'm developing a website that asks the user to submit a keyword for a search. The results should display matches for this keyword, but also show matches for related keywords (in order of relevenace!). I'm planning on building up a library of which search terms users use in the same sessions (e.g. if someone searches for "it jobs" and "php jobs", I'll know the terms are correlated), and I'll also measure the click-through rates of the items on the results list. I've been spending all weekend trying to map out the design for this but it's proving incredibly complicated and I think the solution is likely to be on the internet somewhere already?! Please could someone point me in the right direction if you've come accross this problem before? Thanks a million, Stu Hey guys for a project im making a search filter function. Only one filter seems to be working and that's the genre filter :(
This is my code:
function filterFilms(){ global $conn; $loop = 0; if(isset($_POST['titel']) && !empty($_POST['titel'])){ $titel = sanatize($_POST['titel']); } if(isset($_POST['genre']) && !empty($_POST['genre'])){ $genre = sanatize($_POST['genre']); } $sql = "SELECT TOP 20 * From Movie Inner Join Movie_Director On Movie_Director.movie_id = Movie.movie_id Inner Join Movie_Genre On Movie_Genre.movie_id = Movie.movie_id Inner Join Person On Movie_Director.person_id = Person.person_id"; if(isset($titel) && !empty($titel)){ if($loop == 0){ $sql .= " WHERE ( title = ':titel' OR title like ':titel')"; $loop++; } else{ $sql .= " AND ( title = ':titel' OR title like ':titel')"; } } if(isset($genre) && !empty($genre)){ if($loop == 0){ $sql .= " WHERE genre_name = :genre"; $loop++; } else{ $sql .= " AND genre_name = :genre"; } } $query = $conn->prepare($sql); if(isset($titel) && !empty($titel)){ $query->bindValue('titel', $titel,PDO::PARAM_STR); } if(isset($genre) && !empty($genre)){ $query->bindParam('genre', $genre,PDO::PARAM_STR); } $query->execute(); $rows = $query->fetchAll(); return $rows; }
Anyone any idea??
OK guys so I have my final project for school due next quarter and Its a database management application. I'm dont the upload edit delete scripting but now I need to do the search feature on the front end. I have a basic understanding of the search abilities in PHP but what i'd love to do is create something like Istockphoto.com and many other inventory sites that allow for a "search" field and also a filter. I'd assume there needs to be global variables that will set and adjust the query as things are checked or filled out. does anyone know of any examples/tutorials/demos that I can browse to start figuring this out? Thanks This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=307001.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=320638.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=322686.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=353613.0 hey guys, i have a search bar i am implementing into my navmenu but keeping getting errors returned and im not sure why This is the code in my navmenu to display the search bar Code: [Select] echo '<form action="search.php" method="post">Search: <input type="text" name="term" /> <input type="submit" name="submit" value="Search"/>'; Code: [Select] Here is the php file that query's the search $term = $_POST['term']; $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query = mysqli_query("select * from ob_listings where subject like '%$term%' or description like '%$term%' "); while ($row = mysql_fetch_array($dbc, $query)){ echo 'Subject: '.$row['subject']; echo '<br/> Date: '.$row['date']; echo '<br/> Price: '.$row['price']; echo '<br/> City: '.$row['city']; echo '<br/><br/>'; } any help is much appreciated here are the errors being returned Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\vhosts\HeadFirst\ourbazzar\search.php on line 16 (line 16 is the $query) Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in C:\vhosts\HeadFirst\ourbazzar\search.php on line 17 (line 17 is the while loop) |