PHP - Help With Search Function (php/mysql)
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 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?
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:
Need some help I have 2 tables in a database and I need to search the first table and use the results from that search, to search another table, can this be done? and if it can how would you recommend that I go about it? Thanks For Your Help Guys! The result pages is supposed to have pagination like google help me please
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. 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 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 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? 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. Won't let me type in this box more then 1 line . See Post 3,4 Thanks 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 <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 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=346179.0 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%'"); Hello friends,
I am a novice in php. Though I create 2 scripts:
1. students registration form
2. search students by Registration Number
Our students' Registration Numbers are as follows: nifeA001, nifeA002 & so on...
But when someone enter just "nife" or "n" or "A" etc all the students's data is showing.
I want that students can search data by entering only Full Registration Number not a Part.
I am placing the search.php code below. Please help me out....
----------------- Search.php ------------------
<?php
mysql_connect("localhost", "root", "") or die("could not connect");
mysql_select_db("student") or die("could not connect");
//collect
if(isset($_POST['search'])) {
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i", "", $searchq);
//here
$query = mysql_query("SELECT * FROM user WHERE registration LIKE '%$searchq%'") or die("could not search!");
$count = mysql_num_rows($query);
if($count == 0){
$output = 'There was no search results!';
}else{
while($row = mysql_fetch_array($query)) {
$fname = $row['firstname'];
$lname = $row['surname'];
$id = $row['registration'];
$output .= '<div> '.$id.' '.$fname.' '.$lname.'</div>';
}
}
}
?>
<html>
<head>
</head>
<body>
<form action="form.php" method="post">
<input type="text" name="search" placeholder="search for students.."
<input type="submit" value=">>" />
</form>
<?php print("$output");?>
</body>
</html>
Edited by NasimUddinAhmmad, 13 January 2015 - 05:43 AM. I found an article on how to implement a mysql search (http://www.iamcal.com/publish/articles/php/search/) and it seemed like a good way to go, but I can't get it up and running. Here is my code: Code: [Select] <?php $db_host = 'localhost'; $db_user = 'username'; $db_pwd = 'password'; $database = 'dbname'; $table = 'Principals'; if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); $searchterms = 'dorr oliver'; function search_split_terms($terms){ $terms = preg_replace("/\"(.*?)\"/e", "search_transform_term('\$1')", $terms); $terms = preg_split("/\s+|,/", $terms); $out = array(); foreach($terms as $term){ $term = preg_replace("/\{WHITESPACE-([0-9]+)\}/e", "chr(\$1)", $term); $term = preg_replace("/\{COMMA\}/", ",", $term); $out[] = $term; } return $out; } function search_transform_term($term){ $term = preg_replace("/(\s)/e", "'{WHITESPACE-'.ord('\$1').'}'", $term); $term = preg_replace("/,/", "{COMMA}", $term); return $term; } function search_escape_rlike($string){ return preg_replace("/([.\[\]*^\$])/", '\\\$1', $string); } function search_db_escape_terms($terms){ $out = array(); foreach($terms as $term){ $out[] = '[[:<:]]'.AddSlashes(search_escape_rlike($term)).'[[:>:]]'; } return $out; } function search_perform($terms){ $terms = search_split_terms($terms); $terms_db = search_db_escape_terms($terms); $terms_rx = search_rx_escape_terms($terms); $parts = array(); foreach($terms_db as $term_db){ $parts[] = "Principals RLIKE '$term_db'"; } $parts = implode(' OR ', $parts); $sql = "SELECT * FROM Principal WHERE $parts"; $rows = array(); $result = mysql_query($sql); while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $row[score] = 0; foreach($terms_rx as $term_rx){ $row[score] += preg_match_all("/$term_rx/i", $row[Principals], $null); } $rows[] = $row; } uasort($rows, 'search_sort_results'); return $rows; } function search_rx_escape_terms($terms){ $out = array(); foreach($terms as $term){ $out[] = '\b'.preg_quote($term, '/').'\b'; } return $out; } function search_sort_results($a, $b){ $ax = $a[score]; $bx = $b[score]; if ($ax == $bx){ return 0; } return ($ax > $bx) ? -1 : 1; } function search_html_escape_terms($terms){ $out = array(); foreach($terms as $term){ if (preg_match("/\s|,/", $term)){ $out[] = '"'.HtmlSpecialChars($term).'"'; }else{ $out[] = HtmlSpecialChars($term); } } return $out; } function search_pretty_terms($terms_html){ if (count($terms_html) == 1){ return array_pop($terms_html); } $last = array_pop($terms_html); return implode(', ', $terms_html)." and $last"; } # # do the search here... # $results = search_perform($searchterms); $term_list = search_pretty_terms(search_html_escape_terms(search_split_terms($searchterms))); The table name is 'Principals' and the field name I am trying to search is 'Principal'. I am getting an error on the line: while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ The error is: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Can anyone shed some light on this for me? Hey guys, I'm a newbie to PHP and MySql, and I need some help! For the record, I am a web developer and designer, who always put off learning , due to fear, but realized I had to do it. Anyways, my problem is this. I am creating a website, where there has to be a seach box where people can lookup names, and or keywords, that are stored into my db. I've googled it a billion times, and got everything to almost work. I know how to set-up a database, tables, insert info, and all the real basics of mysql. I am running my site on MAMP right now, and here is the code that I am trying to use. <?php /* DON'T DISPLAY ANY PHP ERRORS OR WARNINGS (optional) comment out in development -----------------------------------------------*/ error_reporting(0); /*DATABASE INFO --------------------------*/ $hostname_logon = 'localhost'; //Database server LOCATION $database_logon = ''; //Database NAME $username_logon = ''; //Database USERNAME $password_logon = ''; //Database PASSWORD /*MYSQL TABLE TO SEARCH --------------------------*/ //update these values to table you want to search $db_table = ''; //TABLE NAME $row_id = ''; //TABLE ROW ID $title_field = ''; //FIELD CONTAINING ITEM TITLE $content_field = ''; //FIELD CONTAINING ITEM CONTENT $link_field = ''; //FIELD CONTAINING ITEM URL $limit = 10; //NUMBER OF RESULTS PER PAGE /*SEARCH SCRIPT FILENAME --------------------------*/ //get the name of this file,so you can name this file whatever you want. This is used in the action parameter of the search form $currentFile = $_SERVER["SCRIPT_NAME"]; $parts = explode('/', $currentFile); $currentFile = $parts[count($parts) - 1]; /*CONNECT TO THE DATABASE --------------------------*/ //open database connection $connections = mysql_connect($hostname_logon, $username_logon, $password_logon) or die ( "Unabale to connect to the database" ); //select database mysql_select_db($database_logon) or die ( "Unable to select database!" ); /*GET SEARCH PARAMETERS --------------------------*/ //get the search parameter from URL $var = mysql_real_escape_string(@$_REQUEST['q']); //get pagination $s = mysql_real_escape_string(@$_REQUEST['s']); //set keyword character limit if(strlen($var) < 3){ $resultmsg = "<p>Search Error</p><p>Keywords with less then three characters are omitted...</p>" ; } //trim whitespace from the stored variable $trimmed = trim($var); $trimmed1 = trim($var); //separate key-phrases into keywords $trimmed_array = explode(" ",$trimmed); $trimmed_array1 = explode(" ",$trimmed1); // check for an empty string and display a message. if ($trimmed == "") { $resulterror = "<p>Search Error</p><p>Please enter a search...</p>" ; } // check for a search parameter if (!isset($var)){ $resulterror = "<p>Search Error</p><p>We don't seem to have a search parameter! </p>" ; } //make sure search keyword is at least 2 characters. (buggy if not) if(strlen($trimmed) < 2){ $resulterror = "<p>Search Error</p><p>Your keyword has to be at least two characters long! </p>" ; } /*CREATE SEARCH FORM --------------------------*/ $search_form = '<form class="search-form" action="'.$currentFile.'" method="GET"> <div> <input name="q" type="text" value="'.$q.'"><input name="search" type="submit" value="Search"> </div> </form>'; /*DISPLAY QUERY ERRORS OR DO THE SEARCH --------------------------------------------*/ if($resulterror){ $resultmsg = $resulterror; }else{ // Build SQL Query for each keyword entered foreach ($trimmed_array as $trimm){ // MySQL "MATCH" is used for full-text searching. Please visit mysql for details. $query = "SELECT *, MATCH (".$title_field.",".$content_field.") AGAINST ('".$trimm."') AS score FROM ".$db_table." WHERE MATCH (".$title_field.",".$content_field.") AGAINST ('+".$trimm."' IN BOOLEAN MODE) HAVING score > 0.01 ORDER BY score DESC"; // Execute the query to get number of rows that contain search kewords $numresults=mysql_query ($query) or die ("Error in query: $query. " . mysql_error()); $row_num_links_main =mysql_num_rows ($numresults); //If MATCH query doesn't return any results due to how it works do a search using LIKE if($row_num_links_main < 1){ $query = "SELECT * FROM ".$db_table." WHERE ".$title_field." LIKE '%".$trimm."%' OR ".$content_field." LIKE '%".$trimm."%' ORDER BY ".$row_id." DESC" ; $numresults=mysql_query ($query); $row_num_links_main =mysql_num_rows ($numresults); } // next determine if 's' has been passed to script, if not use 0. // 's' is a variable that gets set as we navigate the search result pages. if (empty($s)) { $s=0; } // now let's get results. $query .= " LIMIT $s,$limit" ; $numresults = mysql_query ($query) or die ("Error in query: $query. " . mysql_error()); $row= mysql_fetch_array ($numresults); //store record id of every item that contains the keyword in the array we need to do this to avoid display of duplicate search result. do{ $adid_array[] = $row[ 'news_id' ]; }while( $row= mysql_fetch_array($numresults)); } //end foreach /*Display a message if no results found --------------------------*/ if($row_num_links_main == 0 && $row_num_links_main1 == 0){ $resultmsg = "<p>Search results for: ". $trimmed."</p><p>Sorry, your search returned zero results</p>" ; } //delete duplicate record id's from the array. To do this we will use array_unique function $tmparr = array_unique($adid_array); $i=0; foreach ($tmparr as $v) { $newarr[$i] = $v; $i++; } //total number of results $row_num_links_main = $row_num_links_main + $row_num_links_main1; if($resultmsg != ""){ $resultmsg = "<p>Search results for: <strong>" . $var."</strong></p>"; } /* FETCH RESULTS BASED ON THE ID --------------------------------------------*/ foreach($newarr as $value){ // EDIT HERE and specify your table and field unique ID for the SQL query $query_value = "SELECT * FROM ".$db_table." WHERE ".$row_id." = '".$value."'"; $num_value=mysql_query ($query_value); $row_linkcat= mysql_fetch_array ($num_value); $row_num_links= mysql_num_rows ($num_value); //create summary of the long text. For example if the field2 is your full text grab only first 130 characters of it for the result $introcontent = strip_tags($row_linkcat[$content_field]); $introcontent = substr($introcontent, 0, 130)."..."; //now let's make the keywods bold. To do that we will use preg_replace function. //Replace field $title = preg_replace ( "'($var)'si" , "<strong>\\1</strong>" , $row_linkcat[ $title_field] ); $desc = preg_replace ( "'($var)'si" , "<strong>\\1</strong>" , $introcontent); //COMMENT OUT THIS LINE: If using database ID field to drive links $link = preg_replace ( "'($var)'si" , "<strong>\\1</strong>" , $row_linkcat[$link_field] ); //UNCOMMENT and EDIT THIS LINE: If using database ID field to drive links //$link = 'http://yourdomain.com/pageid='. $row_linkcat[$link_field]; foreach($trimmed_array as $trimm){ if($trimm != 'b' ){ $title = preg_replace( "'($trimm)'si" , "<strong>\\1</strong>" , $title); $desc = preg_replace( "'($trimm)'si" , "<strong>\\1</strong>" , $desc); $link = preg_replace( "'($trimm)'si" , "<strong>\\1</strong>" , $link); }//end highlight }//end foreach $trimmed_array //format and display search results $resultmsg.= '<div class="search-result">'; $resultmsg.= '<div class="search-title"><a href="'.$link.'">'.$title.'</a></div>'; $resultmsg.= '<div class="search-text">'; $resultmsg.= $desc; $resultmsg.= '</div>'; $resultmsg.= '<a href="'.$link.'" class="search-link">'; $resultmsg.= $link; $resultmsg.= '</a>'; $resultmsg.= '</div>'; } //end foreach $newarr /* CREATE PAGINATION --------------------------------------------*/ if($row_num_links_main > $limit){ // next we need to do the links to other search result pages if ($s >=1) { // do not display previous link if 's' is '0' $prevs=($s-$limit); $resultmsg.= '<div class="search-previous"><a href="'.$PHP_SELF.'?s='.$prevs.'&q='.$var.'">Previous</a></div>'; } // check to see if last page $slimit =$s+$limit; if (!($slimit >= $row_num_links_main) && $row_num_links_main!=1) { // not last page so display next link $n=$s+$limit; $resultmsg.= '<div class="search-next"><a href="'.$PHP_SELF.'?s='.$n.'&q='.$var.'">Next</a></div>'; } }//end if $row_num_links_main > $limit }//end if no errors ?> <?php //display form echo $search_form; //display results echo $resultmsg; ?> I know that this might be asking a lot, but can someone who is smarter than me please give me instructions on how to set this up. I am at a complete loss. I've tried everything. I can connect to the db, and all, but it returns errors, and or blank screens. I will owe everyone. Thank you. Hello I wonder if it is possible to make a search form with different fields where all conditions should be met if the field is set. I have this code: $sel = "SELECT * FROM database "; $sel .= "WHERE ((test1 = '$test1' "; $sel .= "AND test2 = '$test2' "; $sel .= "AND test3 = '$test3' "; $sel .= "ORDER BY id "; $query = mysql_query($sel) or die(mysql_error()); if (mysql_num_rows($query) == 0){ echo ("No result"); exit; When I use this and leave for example 1 field empty I get the error: No result. Is it possible to make smothing so the condition only should be met if the field is set? So If test1 and test3 are set these condition should be met.. I hope you can help! Thanks in advance! - Frederik |