PHP - Help With Search Function
Hi guys! I want to improve the search function of a wordpress site with AliPlugin. The products shown are completely off topic, you have to be very accurate to get what you need, if you are too accurate of course, you will get nothing.
The site is: http://www.beta.cfcbazar.com Its the site for testing.
Can anyone help me please? Similar TutorialsHi all How do I modify the below code to search multiple tables in mySQL database? $query = "select * from store_items where description like \"%$trimmed%\" or title like \"%$trimmed%\" or dimensions like \"%$trimmed%\" order by id ASC"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); It is for a search function and I need it to search another table called 'about_text' and 'faq_text' Thanks Pete I have been using this code which i found on here which I have gotten to work with my website but I would just like to know how I can make it so that when I click the search button it can take me to a new page which will show the results in a table. Code: [Select] <?php // Set up our error check and result check array $error = array(); $results = array(); // First check if a form was submitted. // Since this is a search we will use $_GET if (isset($_GET['search'])) { $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 3) { $error[] = "Search terms must be longer than 3 characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } // If there are no errors, lets get the search going. if (count($error) < 1) { $searchSQL = "SELECT id, product_name, product_price, product_description FROM product WHERE "; // grab the search types. $types = array(); $types[] = isset($_GET['name'])?"`product_name` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['price'])?"`product_price` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['description'])?"`product_description` LIKE '%{$searchTermDB}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) $types[] = "`product_name` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked $andOr = isset($_GET['matchall'])?'AND':'OR'; $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `product_name`"; // order by title. $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "The search term provided {$searchTerms} yielded no results."; }else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$i}: {$row['product_name']}<br />{$row['product_price']}<br />{$row['product_description']}<br /><br />"; $i++; } } } } <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="get" name="searchForm" id="searchForm"> Search For: <input type="text" name="search" value="<?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?>" /> <br /> <br /> <input type="submit" name="submit" value="Search!" /> </form> <?php echo (count($results) > 0)?"Your search term: {$searchTerms} returned:<br /><br />" . implode("", $results):""; ?> I would be very grateful if someone could help me to get this done. Edit (KP): Next time, please use code tags. Ok i have seen many solutions for using a search function to post onto webpage directly from the mysql db but my question is
is there a way to seach the results that were already outputted via a php query, for instance i have a query that returns
1 MisFit_Kay1 811 2 sajoma 806 3 Atlfan 708 4 karlsbad70 633 5 Booo 570 6 MisFit_Mimi_shg 541 7 PRO_Viking 540 8 tm7_cryzal 540 9 TM7__mina 499 10 PRO_DRFRANK 488 11 PRO_FLAK 488 12 Mhoram 464 13 TM7__CEDAR 462 14 ProSultan 456 15 UBG_Steely1 450but with lots more results now what im hoping for is a point in a direction where i could add a search box that will highlight the name from the list provided . any help will be appreciated Edited by Justafriend, 20 October 2014 - 01:56 AM. Hi, im trying to do a search function that will search through the database Examples : table game with id, name I want to get the ID by searching with keywords BUT my keywords is like 'battle field' and I search only 'battle' How do I get battle field ID from the database with just 'battle' ? Please help me out or show me tutorials. thanks. hi im just trying to do a search on a database and display results based on what the user selected: form code: Code: [Select] html> <body> <form action="search.php" method="POST"> Type of property: <select name="Type_of_Property"> <option>Terraced</option> <option>Detached</option> <option>Semi-Detached</option> <option>Bungalow</option> <option>Flat </option> </select> <p><input type="submit" value="Send Details" name="B1"></p> </form> php code: Code: [Select] <html> <body> <?php error_reporting(E_ALL); mysql_connect("localhost", "root") or die(mysql_error()); // makes a connection mysql_select_db("estate_agents") or die('I cannot connect to the database because: ' . mysql_error()); //conects to the database $result = mysql_query("SELECT * FROM properties WHERE Type_of_Property ='".$_POST['Type_of_Property']); echo "<table border=1>\n"; echo "<tr><td>Address 1</td><td>Address 2</td><td>Postcode</td><td>Type of Property</td><td>Number of Bedrooms</td><td>Number of Bathrooms</td></tr>\n"; while ($row = mysql_fetch_row($result)) { } print "Data base updated with: " .$_POST["Type_of_Property"] ; ?> </body> </html> the propbelm im having is being able to display the results in the table in the while loop any help is appreciated thank you I was showing a friend what I've been working on, and as I watched him type in an entry to search - then not get a result that I know was indeed in the database I realized I needed to accommodate "user laziness." He didn't use punctuation. So I'm trying to figure out how to make that a nonfactor in searches. In other words, my database may have an entry called "St. Patrick's Cathedral" If somebody types "st patricks cathedral" I want the result to still show up. Here's what I'm using right now: Code: [Select] if(isset($_POST[submitted])) { $item = $_REQUEST['find']; $filter1 = trim($_POST['filter1']); if ($filter1 == 'sci-names') { $data = mysql_query("SELECT * FROM table WHERE CONCAT(taxonomic_genus,' ',scientific_name) LIKE '%$item%'"); So I have a basic search form that goes through and does a mySQL like '%$sanitizedInput%' to column in the table. The problem I have is that if I have two rows, one with a value "green" and the second "blue", and I do a search for "green", it shows the green result, if I do a search for "blue", it shows the blue result, but if i do a search for "green blue" it returns no results. Any ideas on how to fix this? Hi, I am trying to build a search function and so far I have it working with just one DB field but I need it to search for different fields. This is my search form: Code: [Select] <form action="t_articulo_Results.php" method="get" name="SearchForm" id="SearchForm"> <label> <input type="text" name="S_articulo_esp" id="S_articulo_esp" value="search" size="30" /> <input type="hidden" name="Search" id="Search" value="Buscar" /> </label> </form> where the field "S_articulo_esp" is a text field to enter the search criteria. This is the code on my results page inclung query: Code: [Select] <?php $MySearch_DefaultWhere = ""; if (!session_id()) session_start(); if ((isset($_GET["Search"]) && $_GET["Search"] != "")) { $MySearch = new FilterDef; $MySearch->initializeQueryBuilder("MYSQL","1"); //keyword array declarations //comparison list additions $MySearch->addComparisonFromEdit("company_name","S_articulo_esp","AND","Includes",0); //save the query in a session variable if (1 == 1) { $_SESSION["MySearch_t_articulo_Results"]=$MySearch->whereClause; } } else { $MySearch = new FilterDef; $MySearch->initializeQueryBuilder("MYSQL","1"); //get the filter definition from a session variable if (1 == 1) { if (isset($_SESSION["MySearch_t_articulo_Results"]) && $_SESSION["MySearch_t_articulo_Results"] != "") { $MySearch->whereClause = $_SESSION["MySearch_t_articulo_Results"]; } else { $MySearch->whereClause = $MySearch_DefaultWhere; } } else { $MySearch->whereClause = $MySearch_DefaultWhere; } } $MySearch->whereClause = str_replace("\\''", "''", $MySearch->whereClause); $MySearchwhereClause = ''; ?> <?php $maxRows_RecordSett_articulo = 10; $pageNum_RecordSett_articulo = 0; if (isset($_GET['pageNum_RecordSett_articulo'])) { $pageNum_RecordSett_articulo = $_GET['pageNum_RecordSett_articulo']; } $startRow_RecordSett_articulo = $pageNum_RecordSett_articulo * $maxRows_RecordSett_articulo; mysql_select_db($database_MySQLconnect, $MySQLconnect); $query_RecordSett_articulo = "SELECT id_cliente, company_name, cliente_calle, cliente_numero, cliente_local, cliente_poblacion, cliente_cp, cliente_pais, cliente_tel, cliente_fax, cliente_movil, cliente_personadecontacto, cliente_email, cliente_web FROM t_clientes ORDER BY company_name ASC"; setQueryBuilderSource($query_RecordSett_articulo,$WADbSearch1,false); $query_limit_RecordSett_articulo = sprintf("%s LIMIT %d, %d", $query_RecordSett_articulo, $startRow_RecordSett_articulo, $maxRows_RecordSett_articulo); $RecordSett_articulo = mysql_query($query_limit_RecordSett_articulo, $MySQLconnect) or die(mysql_error()); $row_RecordSett_articulo = mysql_fetch_assoc($RecordSett_articulo); if (isset($_GET['totalRows_RecordSett_articulo'])) { $totalRows_RecordSett_articulo = $_GET['totalRows_RecordSett_articulo']; } else { $all_RecordSett_articulo = mysql_query($query_RecordSett_articulo); $totalRows_RecordSett_articulo = mysql_num_rows($all_RecordSett_articulo); } $totalPages_RecordSett_articulo = ceil($totalRows_RecordSett_articulo/$maxRows_RecordSett_articulo)-1; ?> please note this line Code: [Select] $MySearch->addComparisonFromEdit("company_name","S_articulo_esp","AND","Includes",0);//comparison list additions because here is where I am getting confused . How can I add more fields to it? Thanks This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=346179.0 <script type="text/javascript"> function listBoxSearch(){ var input = document.getElementById('searchBox'), output = document.getElementById('listBoxF'); if(input.value != ''){ for (var i = 0; i < output.options.length; i++){ if(output.options[i].text.substring(0, input.value.length).toUpperCase() == input.value.toUpperCase()){ output.options[output.options.length] = new Option(output.options[i].innerHTML, output.options[i].text); } } if (output.options.length == 1) { output.selectedIndex = 0; } } } </script>It dosen`t work. It should work like this[DEMO in attached filed] Attached Files listbox_with_keybord_search.htm 7.9KB 3 downloads Won't let me type in this box more then 1 line . See Post 3,4 Thanks I'm trying to build a search function that will search all columns in a table. Here is what I've got: Code: [Select] if (isset($_POST['submitted'])) { $q = "SELECT * FROM children "; if(isset($_POST['query'])) { $q .= "WHERE "; $all = "SELECT * FROM children WHERE 1"; $r_all = mysqli_query($dbc, $all); while ($field = $r_all->fetch_field()) { // Get field headers for building query $f_name = "{$field->name} LIKE {$_POST['query']},:"; // Build query with search string $fn = explode(":",$f_name); // Need to convert $f_name to an array but this does not convert it to a single array but multiple arrays $q .= implode("OR", $fn); // Need to insert OR for the db query } // End while ($field = $r_all->fetch_field()) } // End if(isset($_POST['query'])) } // End if (isset($_POST['submitted'])) The explode function is what is not working for me. It gives me this (sam is the search string I entered into the form): Code: [Select] Array ( [0] => child_id LIKE sam, [1] => ) Array ( [0] => first_name LIKE sam, [1] => ) Array ( [0] => second_name LIKE sam, [1] => ) Array ( [0] => last_name1 LIKE sam, [1] => ) Array ( [0] => last_name2 LIKE sam, [1] => ) Array ( [0] => gender LIKE sam, [1] => ) Array ( [0] => dob LIKE sam, [1] => ) so instead of getting one array with each string being a value I get multiple arrays. Any ideas?
Looking for help with a small task for my weather station website.
Want to see on my website a table with current temperature or other types of measurements for each hour. A small fee is usually given.
the website:
Examples of desired solutions:
I' stuck with writing function for searching replaced numbers and would really appreciate if someone can tell me what I'm doing wrong.
My table structure looks like:
CREATE TABLE servis.zamjene_brojeva ( id INT(11) NOT NULL AUTO_INCREMENT, vrijeme TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, pocetni_broj VARCHAR(55) DEFAULT NULL, zamjenski_broj VARCHAR(55) DEFAULT NULL, glavni_broj VARCHAR(55) DEFAULT NULL, postoji_zamjena INT(1) DEFAULT NULL, PRIMARY KEY (id) )My function looks like this: //funkcija za traženje zamjene brojeva function zamjena_broja($kataloski_broj){ //Traženje zamjenskog broja $upit_zamjena = "SELECT pocetni_broj, zamjenski_broj, glavni_broj FROM zamjene_brojeva WHERE glavni_broj = '$kataloski_broj'"; $rezultat_zamjena = mysql_query($upit_zamjena) or die (mysql_error()); $row = mysql_fetch_array($rezultat_zamjena); $kataloski_broj = $row["zamjenski_broj"]; $broj_zamjena = mysql_num_rows($rezultat_zamjena); return $kataloski_broj; //Traženje druge zamjene broja if ($broj_zamjena <> 0) { $upit_zamjena = "SELECT pocetni_broj, zamjenski_broj, glavni_broj FROM zamjene_brojeva WHERE pocetni_broj = '$kataloski_broj'"; $rezultat_zamjena = mysql_query($upit_zamjena) or die (mysql_error()); $broj_zamjena2 = mysql_num_rows($rezultat_zamjena); $row2 = mysql_fetch_array($rezultat_zamjena); $kataloski_broj = $row2["zamjenski_broj"]; return $kataloski_broj; //Traženje treće zamjene if ($broj_zamjena2 <> 0) { $upit_zamjena = "SELECT pocetni_broj, zamjenski_broj, glavni_broj FROM zamjene_brojeva WHERE pocetni_broj = '$kataloski_broj'"; $rezultat_zamjena = mysql_query($upit_zamjena) or die (mysql_error()); $broj_zamjena3 = mysql_num_rows($rezultat_zamjena); $row3 = mysql_fetch_array($rezultat_zamjena); $kataloski_broj = $row3["zamjenski_broj"]; return $kataloski_broj; } } }In pocetni_broj is old number and in glavni_broj is new number. But it can happen that number in glavni_broj is old and I need to search in pocetni_broj to see if there is even newer number and it can happen 5 or 6 times like that. I need to find all the numbers that are connected, but I'm not getting that. What am I doing wrong? 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??
//get the search variable from the FORM$function_keywords = mysql_real_escape_string($_POST['function_keywords']);//trim whitespace from the stored variable$trimmed = trim($function_keywords);//separate key-phrases into keywords$trimmed_keywords = explode(" ",$trimmed);// Build SQL Query for each keyword enteredforeach ($trimmed_keywords as $trimm){// MySQL "MATCH" is used for full-text searching.//this code is ebv weird , should check out soon!$query = "SELECT * , MATCH (function_description) AGAINST ('".$trimm."') AS score FROM table_name WHERE MATCH (function_description) AGAINST ('+".$trimm."') ORDER BY score DESC "; // Execute the query to get number of rows that contain search kewords $results=mysql_query ($query,$connection); $row=""; $row =$row . mysql_fetch_array($results, MYSQL_BOTH);} $row_num=mysql_num_rows ($row); if($row_num < 1){ redirect("welcome.php?search=fail"); } else if ($row_num > 1){ ?> <html> <head> <title>Search results</title> </head> <body> <?php foreach($row as $row_result){ echo "function name : {$row_result['function_name']} --- function Description : {$row_result['function_description']}<br/><br/>"; }?> </body> </html>() IS there an error on the SQL syntax ? or its about ? : Code: [Select] $results=mysql_query ($query,$connection); $row=""; $row =$row . mysql_fetch_array($results, MYSQL_BOTH); } $row_num=mysql_num_rows ($row); The result pages is supposed to have pagination like google help me please
I require a page to be added to my website. This page will facilitate a refined search via Google, Bing and Yahoo search engine simultaneously , show the top 5 of each engine. Is this possible using php ? Thank's |