PHP - Search On Typing
Hi all,
I'm using PHP and MS-SQL and i'm trying to make a search input text field. For example the user writes P in one country field and i need that appears a dropdown with the name of countries that start with P, for example, Portugal, Poland and so on. Then user can choose one of them. How can i do this? Thanks in advance and regards Hugo Similar TutorialsThis topic has been remastered in brilliant HD quality in JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=356870.0 Hi, suppose the user requests a page www.foo2.php. Now if it is a link embedded in another page, say www.foo1.php, then Javascript can send the server browser info before furnishing the page. But is it possible to let the server know which browser is being used when the user requests the page by just typing the url http://www.foo2.php and hitting enter? I spent the last hour or so typing this code up, and for some reason I am getting a query error. I have reviewed & revised the code up and down for the past half hour and can't seem to figure out the problem. Can someone look after this for me and tell me what I could be doing wrong? Yes, I know my code is a bit sloppy and may use bad practice techniques, but it works for me. Its a survey that I coded so I could collect data and place it on CPA ad listings. So I need this so work at some point soon. My code: <?php $user = $_POST['user']; $email = $_POST['email']; $password = $_POST['pass']; $paypal = $_POST['paypal']; $q1 = $_POST['q1[favsite]']; $q2 = $_POST['q2[isp]']; $q21 = $_POST['q2.1[bill]']; $email_services = $_POST['email_services']; $ebay = $_POST['ebay']; $amazon = $_POST['amazon']; $q6 = $_POST['q6[purchase]']; $q7 = $_POST['q7[social]']; $q8 = $_POST['q8[bookmarks]']; $q9 = $_POST['q9[search]']; $q10 = $_POST['q10[homepage]']; $q11 = $_POST['q11[5topsites]']; $q12 = $_POST['q12[state]']; if ($_POST['fin'] == "complete") { $dbc = mysqli_connect('localhost', 'root', 'password', 'database') or die('Could not connect'); $query = "INSERT INTO user_data (id, user, email, password, paypal, q1[favsite], q2[isp], q21[bill], email_services, ebay, amazon, q6[purchase], q7[social], q8[bookmarks], q9[search], q10[homepage], q11[5topsites], q12[state]) VALUES ('$user', '$email', '$password', '$paypal', '$q1', '$q2', '$q21', '$email_services', '$ebay', '$amazon', '$q6', '$q7', '$q8', '$q9', '$q10', '$q11', '$q12')"; mysqli_query($dbc,$query) or die('Error querying database'); include_once("../phpmailer/class.phpmailer.php"); $mail = new PHPMailer; $mail->ClearAddresses(); $mail->AddAddress('', ''); $mail->From = ''; $mail->FromName = ''; $mail->Subject = 'Thanks for finishing the survey!'; $mail->Body = "Hello, $user. This is a reminder that you have finished the survey and your credit is currently being processed. Please login to your account at ../../ to view the status of your credit & cash out. "; if ($mail->Send()) { echo "<center>Mail Sent.</center>"; } else { echo $mail->ErrorInfo; } echo "<center><h2>Thanks for completing the survey! Please <a href='login.php'>login</a> to your account to view the status of your credit & cash out.</h2></center>"; } ?> It has nothing to do with PHPMailer, I of course edited the variables just now so all my info wouldnt be public, but everything is fine untill you press submit & I get the or die() error message "Error querying database". What the hell did I do wrong? Is it possible that I cant name variables in the format I used with most of them ($var1 = $_POST['var[desc]']; ? 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 Hello, Does anyone know a tutorial I can follow to create my own search engine over the items I have in my SQL database? I find a lot of tutorials but they are all 'one word searches' which means if you type two words you will get all results that contain either word (too many hits). If the search engine tutorial displays result with AJAX even better. Thanks for help. df Hi 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 am developing a intranet forum in Php and MySQL and I am using ajax to display searched results on the same page but right now I am using query LIKE text% to search in database which is slower. but I want to make it fast search engin which can parse *,+ and show result. Since I am using ajax i am not able to use free search engin,so if possible pls provide a complete solution I have code to search a database of members, I can search by lastname but having a little problem. I want to be able to search by lastname starting with the first letter. (ie: a or b or c or d and so on). As it is right now I can only search by first letter of last name if I add % to the search (ie: a% b% c%) will give me all members with the last names starting with the approiate letter designation. I'm not sure how to handle this, any help would be appreciated. Thanks. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body> <center><table cellspacing="10" cellpadding="10" width="750" border="0"> <h4>Search</h4> <form name="search" method="post" action="<?php $PHP_SELF?>"> Seach for: <input type="text" name="find" /> in <Select NAME="field"> <Option VALUE="lname">Last Name</option> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </form> <?php // check to see if anything is posted if (isset($_POST['find'])) {$find = $_POST['find'];} if (isset($_POST['searching'])) {$searching = $_POST['searching'];} if (isset($_POST['field'])) {$field = $_POST['field'];} //This is only displayed if they have submitted the form if (isset($searching) && $searching=="yes") { echo "<h4>Results</h4><p>"; // If they did not enter a search term we give them an error if (empty($find)) { echo "<p>You forgot to enter a search term"; exit; } // Otherwise we connect to our Database mysql_connect("localhost", "root", "1910") or die(mysql_error()); mysql_select_db("cmc_member") or die(mysql_error()); // We preform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); // Now we search for our search term, in the field the user specified $results = mysql_query("SELECT * FROM members WHERE upper($field) LIKE'$find'"); // And we display the results if($results && mysql_num_rows($results) > 0) { $i = 0; $max_columns = 3; while($row = mysql_fetch_array($results)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product ALIGN='CENTER' if($fname != "" && $fname != null) echo "<td ALIGN='CENTER'><FONT COLOR='red'><b>$fname $lname</b></FONT><br> $address <br> $city $state $zip <br>$phone<br><a href=\"mailto: $email\">$email</a><br></td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches = mysql_num_rows($results); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } //And we remind them what they searched for echo "<b>Searched For:</b> " .$find; } ?> </tr> </table></center> </body> </html> 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 Friends, I want to extract the Search Keyword from the URL, a visitor came from. I am using a PHP CMS and want to show the Keyword on my Blog. So if they search "abcd" from google, i want to extract "abcd" and echo on my blog. Here is the coding i could got hold of, but its not working, not echoing anything <?php function pk_stt2_function_get_delimiter($ref) { $search_engines = array('google.com' => 'q', 'go.google.com' => 'q', 'images.google.com' => 'q', 'video.google.com' => 'q', 'news.google.com' => 'q', 'blogsearch.google.com' => 'q', 'maps.google.com' => 'q', 'local.google.com' => 'q', 'search.yahoo.com' => 'p', 'search.msn.com' => 'q', 'bing.com' => 'q', 'msxml.excite.com' => 'qkw', 'search.lycos.com' => 'query', 'alltheweb.com' => 'q', 'search.aol.com' => 'query', 'search.iwon.com' => 'searchfor', 'ask.com' => 'q', 'ask.co.uk' => 'ask', 'search.cometsystems.com' => 'qry', 'hotbot.com' => 'query', 'overture.com' => 'Keywords', 'metacrawler.com' => 'qkw', 'search.netscape.com' => 'query', 'looksmart.com' => 'key', 'dpxml.webcrawler.com' => 'qkw', 'search.earthlink.net' => 'q', 'search.viewpoint.com' => 'k', 'mamma.com' => 'query'); $delim = false; if (isset($search_engines[$ref])) { $delim = $search_engines[$ref]; } else { if (strpos('ref:'.$ref,'google')) $delim = "q"; elseif (strpos('ref:'.$ref,'search.atomz.')) $delim = "sp-q"; elseif (strpos('ref:'.$ref,'search.msn.')) $delim = "q"; elseif (strpos('ref:'.$ref,'search.yahoo.')) $delim = "p"; elseif (preg_match('/home\.bellsouth\.net\/s\/s\.dll/i', $ref)) $delim = "bellsouth"; } return $delim; } /** * retrieve the search terms from search engine query * */ function pk_stt2_function_get_terms($d) { $terms = null; $query_array = array(); $query_terms = null; $query = explode($d.'=', $_SERVER['HTTP_REFERER']); $query = explode('&', $query[1]); $query = urldecode($query[0]); $query = str_replace("'", '', $query); $query = str_replace('"', '', $query); $query_array = preg_split('/[\s,\+\.]+/',$query); $query_terms = implode(' ', $query_array); $terms = htmlspecialchars(urldecode(trim($query_terms))); return $terms; } /** * get the referer * */ function pk_stt2_function_get_referer() { if (!isset($_SERVER['HTTP_REFERER']) || ($_SERVER['HTTP_REFERER'] == '')) return false; $referer_info = parse_url($_SERVER['HTTP_REFERER']); $referer = $referer_info['host']; if(substr($referer, 0, 4) == 'www.') $referer = substr($referer, 4); return $referer; } $referer = pk_stt2_function_get_referer(); if (!$referer) return false; $delimiter = pk_stt2_function_get_delimiter($referer); if( $delimiter ){ $term = pk_stt2_function_get_terms($delimiter); } echo $term; ?> May someone help? Natasha T Hello. I am working on a php script for searching a database table. I am really new to this, so I used the this tutorial http://www.phpfreaks.com/tutorial/simple-sql-search I managed to get all the things working the way I wanted, except one important and crucial thing. Let me explain. My table consist of three columns, like this: ID(bigint20) title(text) link (varchar255) ============================= ID1 title1 link-1 ID2 title2 link-2 etc... Like I said, I managed to make the script display results for a search query based on the title. Want I want it to do more, but I can't seem to find the right resource to learn how, is to place a "Download" button under each search result with its corresponding link from the table. Here is the code I used. <?php $dbHost = 'localhost'; // localhost will be used in most cases // set these to your mysql database username and password. $dbUser = 'user'; $dbPass = 'pass'; $dbDatabase = 'db'; // the database you put the table into. $con = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($dbDatabase) or trigger_error("Failed to connect to database {$dbDatabase}. Error: " . mysql_error()); // 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 title, link FROM db WHERE title LIKE '%{$searchTermDB}%'"; $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[] = "{$row['title']}<br /> Download - this is the button I want to link to the title results - and maybe other links too - <br /> "; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?> <?php echo (count($error) > 0)?"The following had errors:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?> <form method="GET" action="search?" name="searchForm"> Search for title: <input type="text" name="search" value="<?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?>" /> <input type="submit" name="submit" value="Search" /> </form> <?php echo (count($results) > 0)?"Rezultate lucrari de licenta sau disertatie pentru {$searchTerms} :<br /><br />" . implode("", $results):""; ?> $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$row['title']}<br /> Download - this is the button I want to link to the title results - and maybe other links too - <br /> "; $i++; I would like the results to be displayed like this Results for SearchItem: Result 1 Download | Other link Result 2 Download | Other link etc.... or something like this. So, how do I add the data from the link row into a text(Dowload), within an <a href> tag (well, at least I guess it would go this way) ? My first tries (fueled by my lack of knowledge) where things like $results[] = "{$row['title']}<br /> <a href="{$row['link']}">Download</a> <br /> "; but I keep getting lots of errors, and then I don't know much about arrays and stuff (except basic notions); So there it is. I am really stuck and can't seem to find any workaround for this. Any suggestions? (examples, documentation, anything would do, really) Thanks, Radu Hello All, I want to know how to display results from mysql database by filling in a form. but i have found a tutorial which shows typing in a text box which displays results. if i follow this tutorial will it help me to understand and create php coding to display results for my form? 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! On a website I'm building at the moment I want to have a search bar. At the moment when I make the search I am using the MySQL "LIKE" to compare the user's search with records in a database. However this is only a very basic search. For example if the user is looking for articles on javascript but they mis spell it as "jaavscript" then using "LIKE" won't recognises these two as being similar. Could anyone point me in the direction or some articles or tutorials about how to perform better search with PHP and MySQL? Thanks for any help. Hi there, I'm working on a search bar for my website and I want what ever someone types in, to be like the data in my table column name. My table column name is 'make', my table name is 'stick'. At the moment, my code outputs " your search: "..mysearchterm.." returned zero results", even when i type in the same name as a row in my column. Can anyone make sense of why my code's not performing? Code: [Select] <form id="search" name="search" id="search" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>" /> <input type="text" name="terms" value="Search..." /> <input class="button" type="submit" name="Search" value="Search" /> </form> <?php include_once('connectvars.php'); if (isset($_GET['terms']) && ($_GET['terms'] != 'Search...') ) { $terms = $_GET['terms']; $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die *('Error connecting to MySQL server'); // Query the database. $query = "SELECT sid, type, colour, make FROM stick WHERE make LIKE '%$terms% '"; // Fetch the results. $result=mysqli_query($dbc,$query); // Print the results: $num_rows = mysqli_num_rows($result); // If the results of the query match to 1 or more rows, display the products by their title, price and image. if ($num_rows > 0){ if($result=mysqli_query($dbc,$query)){ $output = Array(); while($row=mysqli_fetch_assoc($result)) { //'<br /> Street: ' .$row['street'].' $output[] = '<ul>'; $output[] = '<li> Type: '.$row['make'] .' Size: '.$row['type'].'<br />Colour: '.$row['colour'] . '" /></li>'; $output[] = '</ul>'; } } echo join('',$output); } // If the results don't match the titles of the table, output this message. else { echo "<h3>Sorry,</h3>"; echo "<p>your search: "" .$terms. "" returned zero results</p>"; } } else { // Tell them to use the search form. echo '<p class="error">Please use the search form at the top of the window to search this site.</p>'; } ?> Thanks. Hi im just querying im tryign to do a simple search on my database and set it so it searches between two price values from a drop down box Code: [Select] html> <body> <form action="bedroomsearch.php" method="POST" > Price: <select name="Price"> <option> 100-300</option> <option> 200-500</option> <option> 400-700</option> <option> 600-900</option> <option> 900+ </option> </select> </br></br> </br></br> <p><input type="submit" value="Send Details" name="TypeSubmit"></p> </form> Code: [Select] $query = "SELECT * FROM properties WHERE Price ='".$_POST['Price']."'"; $result = mysql_query($query); That is the query id use to search for the prices how do i do it so i can search for all the entries between the two values in the drop box? Im trying to make a php page that searchs for whats typed in a field and if it doesnt exits then add. I am tring to use whats below but cant get it to work. Any thoughts <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form name="form1" method="" action=""> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3"><strong>Member Search</strong></td> </tr> <tr> <td width="78">Username</td> <td width="6">:</td> <td width="294"><input name="myusername" type="text" id="myusername"></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Search"></td> </tr> </table> </td> </form> </tr> </table> $myusername = username <?php $con = mysql_connect("mysqlserver","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("dbtest", $con); mysql_query("INSERT INTO partylist (Username, Key) VALUES ($myusername , 'keytest')"); mysql_close($con); ?> I'm working on a script that when you submit the form it returns what group you'd be assigned to based on email. the database table groups has a field called "strings" and we have saved for example @gmail.com and any email containing @gmail.com will be assigned to G Mail Users. I'm having a hard time establishing how I want to do this. The one way I know I can do it is by fetching all the fields and then matching it up using stristr. I was thinking there has to be a better way using the mysql functions. |