PHP - How To Create Search Functionality In Php And Mysql And The Search Result Will Be On Another Page Apart From The Search Page
The result pages is supposed to have pagination like google help me please
Similar TutorialsHello. 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 I have a multiple choice search page which asks visitors to select one or more choices before rendering the search results. It only works in items 1+2 are selected, or 1+2+3, or 1+2+3+4, or 1+2+3+4, etc... I want to make it so that any combination of choices work. Example: Items 1+6 or 2+3+5 or 1+4+6 etc... I have four hours to fix it before my client shows up and need help BADLY. Anyone out there who can help? Whoever can help me... you are the best and I will have a special prayer for you tonight. Here is the coding: <?php } else{ if(!empty($_GET['latt']) && !empty($_GET['long'])) { $condition="SELECT ( 3959 * acos( cos( radians( '".$_GET['latt']."' ) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians( '".$_GET['long']."' ) ) + sin( radians( '".$_GET['latt']."' ) ) * sin( radians( latitude ) ) ) ) as distance,id,membership FROM notary_members "; if(!empty($_GET['s'])) { $a=" where and"; } else { $a=" where"; } if($_GET['edoc']!='') { $condition.=$a." edoc= 'yes'"; } if($_GET['esign']!='') { if($_GET['edoc']!='') $condition.=" and esign= 'yes'"; else $condition.=$a." esign= 'yes'"; } if($_GET['laserprinter']!='') { if($_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and laserprinter= 'yes'"; else $condition.=" laserprinter= 'yes'"; } if($_GET['dualtray']!='') { if( $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and dualtray= 'yes'"; else $condition.=" dualtray= 'yes'"; } if($_GET['error_in']!='') { if($_GET['dualtray']!='' || $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and error_in= 'yes'"; else $condition.=" error_in= 'yes'"; } if($_GET['bg_checked']!='') { if($_GET['error_in']!='' || $_GET['dualtray']!='' || $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and bg_checked= 'yes'"; else $condition.=" bg_checked= 'yes'"; } if($_GET['home_insp']!='') { if($_GET['bg_checked']!='' || $_GET['error_in']!='' || $_GET['dualtray']!='' || $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and home_insp= 'yes'"; else $condition.=" home_insp= 'yes'"; } if($_GET['fingerprint']!='') { if($_GET['home_insp']!='' || $_GET['bg_checked']!='' || $_GET['error_in']!='' || $_GET['dualtray']!='' || $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and fingerprint= 'yes'"; else $condition.=" fingerprint= 'yes'"; } if($_GET['hosp_signing']!='') { if($_GET['fingerprint']!='' || $_GET['home_insp']!='' || $_GET['bg_checked']!='' || $_GET['error_in']!='' || $_GET['dualtray']!='' || $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and hosp_signing= 'yes'"; else $condition.=" hosp_signing= 'yes'"; } if($_GET['jail_signing']!='') { if($_GET['hosp_signing']!='' || $_GET['fingerprint']!='' || $_GET['home_insp']!='' || $_GET['bg_checked']!='' || $_GET['error_in']!='' || $_GET['dualtray']!='' || $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and jail_signing= 'yes'"; else $condition.=" jail_signing= 'yes'"; } if($_GET['im_docs']!='') { if($_GET['jail_signing']!='' || $_GET['hosp_signing']!='' || $_GET['fingerprint']!='' || $_GET['home_insp']!='' || $_GET['bg_checked']!='' || $_GET['error_in']!='' || $_GET['dualtray']!='' || $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='') $condition.=" and im_docs= 'yes'"; else $condition.=" im_docs= 'yes'"; } if($_GET['jail_signing']!='' || $_GET['hosp_signing']!='' || $_GET['fingerprint']!='' || $_GET['home_insp']!='' || $_GET['bg_checked']!='' || $_GET['error_in']!='' || $_GET['dualtray']!='' || $_GET['laserprinter']!='' || $_GET['esign']!='' || $_GET['edoc']!='' || $_GET['im_docs']!='') { $condition.=" and status=1 order by distance asc"; } else { $condition.=$a." status=1 order by distance asc"; } $sql=mysql_query($condition); $num=mysql_num_rows($sql); $getmile=explode(' ',$_GET['miles']); $c=0; while($getidres=mysql_fetch_array($sql)) { if($getidres['distance']<=$getmile[0]) { if($getidres['membership']=='premium') { $prefirst[$getidres['id']]=$getidres['distance']; $c++; } else { $basicfirst[$getidres['id']]=$getidres['distance']; $c++; } } } if(!empty($sql)) { if($c!=0) { if(!empty($prefirst) || !empty($basicfirst)) { ?> 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 seeking to learn more about the noted subject, how to use PHP to allow a user to enter search terms and search a database. I have experimented with this with little results save for errors. Please see code listed below: search.php <? //// filename = search.php <form method="post" action="result.php3"> <select name="metode" size="1"> <option value="row_name1">metode1</option> <option value="row_name2">metode2</option> </select> <input type="text" name="search" size="25"> <input type="submit" value="Begin Searching!!"> </form> ?> results.php //// filename = result.php3 <? $hostname = "mysql7.000webhost.com"; // Usually localhost. $username = "a4542527_root"; // If you have no username, leave this space empty. $password = "*******"; // The same applies here. $usertable = "people"; // This is the table you made. $dbName = "a4542527_test1"; // This is the main database you connect to. MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); @mysql_select_db( "$dbName") or die( "Unable to select database"); ?> <? //error message (not found message) $XX = "No Record Found"; $query = mysql_query("SELECT * FROM $usertable WHERE $metode LIKE '%$search%' LIMIT 0, 30 "); while ($row = mysql_fetch_array($query)) { $variable1=$row["row_name1"]; $variable2=$row["row_name2"]; $variable3=$row["row_name3"]; print ("this is for $variable1, and this print the variable2 end so on..."); } //below this is the function for no record!! if (!$variable1) { print ("$XX"); } //end ?> Upon viewing search.php I receive the error message: Parse error: syntax error, unexpected '<' in /home/a4542527/public_html/search.php on line 3 I believe I may be missing something and am a bit lost. Thank-you in in advance for any help or suggestions. ~Matty Hello all brilliant minds, I'm a new in all this world of DB and coding and always i tried to avoid it because I think it is very hard (I'm trying to change now). problem: I have a text file (log.txt) have data like below ======================================== > rtrv-ls Command Accepted - Processing OXX 12-02-21 08:44:41 EST EAGLE5 42.0.1-63.38.31 rtrv-ls Command entered at terminal #7. ; OXX 12-02-21 08:44:41 EST EAGLE5 42.0.1-63.38.31 L3T SLT GWS GWS GWS LSN APCI (SS7) SCRN SET SET BEI LST LNKS ACT MES DIS SLSCI NIS gtcen1pls 7-010-4 none 1 2 no D 2 off off off no off gtgdv1pls 7-010-5 none 1 2 no D 2 off off off no off > rtrv-sid Command Accepted - Processing OXX 12-02-21 08:43:43 EST EAGLE5 42.0.1-63.38.31 rtrv-sid Command entered at terminal #7. ; OXX 12-02-21 08:43:43 EST EAGLE5 42.0.1-63.38.31 PCA PCI PCN CLLI PCTYPE 010-010-010 7-055-1 01830 crher1p OTHER ; . . may output like this starting always with > =================================================== Then I have SQL DB that have column with "rtrv-ls" and "rtrv-sid" Requirement : A) Use Php to open the .txt file, I used HTML form so the user can upload the file on the browser then B) Search for the column name as pattern C)Send query to MYSQL to update DB with Data for each column D) Query the Mysql for several possible outputs (I've done this part using HTML form and simple php code as below. <?php // If we got a GET request on the page from HTML part of the code, we will want to store the data in a variable e.g $my_country // So country will be passed via GET and will be stored in $my_country variable. $host="localhost"; $con_usr="aomar"; $con_pass="nokia"; if ($_POST) { $user_input = $_POST['my_log'] ; // We use the request to search in Database and return the result, First step we need to connect to the database // $connect = mysql_connect ($host,$con_usr,$con_pass); // Then we need to select database to run the query and return the result the connection stored in the $connect ressource // if ($connect) { mysql_select_db("eagle",$connect); // We store the query in variable $query becuase is it quite long text; we actually attach our varaiable $my_log passed from HTML // $query = "SELECT `".$user_input."` FROM `ss7`"; //$update="INSERT INTO ss7 ('".$user_input."') VLAUES ('; // SO if user selected Egypt it will be stored in (name=my_country) variable from HTML and will be send via GET // Then we store the query results in a variable called $result $result = mysql_query ($query) ; $arr= mysql_fetch_array($result); echo nl2br ($arr["$user_input"]); //Finally we return what we want from the array. // Print the output as we wish. in case of row data like STP output, use the nl2br to preserve the output as it was written to MYSQL DB // We need to check if the Query return no value (!$arr) , and print corresponding action } //================SECONED PART WHEN I LOAD THE LOG FILE TO BE STORED IN MYSQL================// //close the db mysql_close ($connect); } ?> <html> <body> <form action = "eagle.php?pmode=my_file" method = "POST" enctype="multipart/form-data> <fieldset> <legend> Enter you log file here and click Save: </br> </legend> <label for="my_file"> This Is My Capture File </label> <input type = "file" name ="my_file" style=margin:auto > </input><br/><br/> <input type="submit" value="Upload file"> </fieldset> </form> </body> </html> <html> <body> <title>Eagle Data Base Store</title> <form action = "eagle.php?pmode=my_log" method = "POST"> <fieldset> <legend> Please Select the DB you would like to retrive </legend> <br/><br/> <input type = "radio" name ="my_log" value = "rtrv-serial-num">Serial-Num</input> <input type = "radio" name ="my_log" value = "rtrv-stp">rtrv-stp</input> <input type = "radio" name ="my_log" value = "rtrv-feat">rtrv-feat</input> <input type = "radio" name ="my_log" value = "rtrv-dstn">rtrv-dstn</input> <input type = "radio" name ="my_log" value = "rtrv-rte">rtrv-rte</input> <input type = "radio" name ="my_log" value = "rtrv-trm">rtrv-trm</input> <input type = "radio" name ="my_log" value = "rtrv-slk">rtrv-slk</input><br/> <br/> <input type = "radio" name ="my_log" value = "rtrv-ls">rtrv-ls</input> <input type = "radio" name ="my_log" value = "rtrv-sccpopts">rtrv-sccpopts</input> <input type = "radio" name ="my_log" value = "rtrv-stpopts">rtrv-stpopts</input> <input type = "radio" name ="my_log" value = "rtrv-gsmopts">rtrv-gsmopts</input> <input type = "radio" name ="my_log" value = "rtrv-cmd">rtrv-cmd</input> <input type = "radio" name ="my_log" value = "rtrv-assoc">rtrv-assoc</input><br/> <br/> <input type = "radio" name ="my_log" value = "rtrv-gpl">rtrv-gpl</input> <input type = "radio" name ="my_log" value = "rtrv-ip-host">rtrv-ip-host</input> <input type = "radio" name ="my_log" value = "rtrv-ip-lnk">rtrv-ip-lnk</input> <input type = "radio" name ="my_log" value = "rtrv-secu-trm">rtrv-secu-trm</input> <input type = "radio" name ="my_log" value = "rtrv-secu-user">rtrc-secu-user</input> <input type = "radio" name ="my_log" value = "rept-stat-sys">rept-stat-sys</input><br/><br/> <input type = "radio" name ="my_log" value = "rept-stat-clk">rept-stat-clk</input> <input type = "radio" name ="my_log" value = "rtrv-ctrl-feat">rtrv-ctrl-feat</input> <input type = "radio" name ="my_log" value = "rtrv-tabl-capacity">rtrv-tabl-capacity</input><br/><br/> <input type = "submit" value = "Show Selected Table"/> </fieldset> </form> </body> </html> ==========================================END OF CODE=========================== *** Sorry for the many comments but I want to be sure I remember why I do that . You help is much appreciated (Please note that need to understand more than I need the Code itself) 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! Hi gents, This will be an easy one for you all! I have a sql select statement and everything functions fine as is, BUT I would like to give users more freedom. Using this sql statement the results only return if the user types the Botanical Name or Common Name of a particular plant exactly as it is spelled in the database: $sql = mysql_query("SELECT PlantID, CommonName FROM plants WHERE BotanicalName='$BotanicalName' OR CommonName='$CommonName' OR Use1='$Use' OR Use2='$Use' OR Use3='$Use' OR Use4='$Use' OR Use5='$Use' ORDER BY CommonName"); What if the user doesn't know the species of a plant and only it's genus or the user only knows Maple tree and not which particular one they are looking for: For example: Plant in Database = Brandywine Red Maple User Search would have to be exactly that "Brandywine Red Maple" for a result to return Ideally I would like the user to be able to type in "Maple" and ALL Maples return Let me know if you need more info 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 I have code for a perv. and next links at the bottom of my search page. Which shows the next ten results however when the next link is clicked the page says please fill in all fields (as if the search box was left empty and the search button was clicked... please help me figure this out... Code: [Select] <?php // Get the search variable from URL $var = $_GET['search']; $searchtype = $_GET['searchtype']; $isbn = "ISBN"; $school = "School"; $title = "Title"; $subject = "Subject"; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=10; // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } //connect to your database $connect = mysql_connect("db","user","pass") or die("Not connected"); //specify database mysql_select_db("user") or die("could not log in"); if ($searchtype == ($title)) { // Build SQL Query $query = "select * from boox where name like \"%$trimmed%\" order by name"; // EDIT HERE and specify your table and field names for the SQL query } elseif ($searchtype == ($school)) { // Build SQL Query $query = "select * from boox where school like \"%$trimmed%\" order by school"; // EDIT HERE and specify your table and field names for the SQL query } elseif ($searchtype == ($isbn)) { // Build SQL Query $query = "select * from boox where isbn like \"%$trimmed%\" order by isbn"; // EDIT HERE and specify your table and field names for the SQL query } elseif ($searchtype == ($subject)) { // Build SQL Query $query = "select * from boox where subject like \"%$trimmed%\" order by subject"; // EDIT HERE and specify your table and field names for the SQL query } $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; echo "<p><a href=\"http://www.google.com/search?q=" . $trimmed . "\" target=\"_blank\" title=\"Look up " . $trimmed . " on Google\">Click here</a> to try the search on google</p>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . "" in "" . $searchtype ."" </p>"; // begin to show results set echo "Results "; $count = 1 + $s ; if ($searchtype = $title) { // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["name"]; echo "$count. $title   </br><table width='297' border='1' align='center'> <tr> <td width='152'>Book Title:</td> <td width='129'>$row[name]</td> </tr> <tr> <td>Author:</td> <td>$row[author]</td> </tr> <tr> <td>ISBN#</td> <td>$row[isbn]</td> </tr> <tr> <td>Date Posted:</td> <td>$row[date]</td> </tr> <tr> <td>Posted By:</td> <td><a href='backpack.php?usr=$row[username]'>$row[username]</a></td> </tr> <tr> <td>School:</td> <td>$row[school]</td> </tr> </table></br>"; $count++ ; } } elseif ($searchtype = $school) { // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["school"]; echo "$count. $title" ; $count++ ; } } elseif ($searchtype = $subject) { // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["subject"]; echo "$count. $title" ; $count++ ; } } elseif ($searchtype = $isbn) { // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["isbn"]; echo "$count. $title" ; $count++ ; } } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&search?q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> hello, was wondering if there is a way to have a search box that searches all data on the current page. similar to what a ctrl+F would do in internet exoplorer 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. I am in need of some help with a simple page search function. In short what i need is a way the user can search for a specific page name from the home index page. My site (local for now) will be constructed as follows: localhost/mysite/index.html 0001.html 0002.html ... 0132.html etc... The subpages will be added/modified externaly and may run into the hundreds of pages. For this reason mySQL will be hard to implement and somewhat overkill especialy for this simple search function. So, is there a way i can type the page to look for "0132" into the field and be forwarded onto the searched page "0132.html" I realise i could just type mysite/0132.html but the page may or may not exist and searching would be tiny bit more elegant. Simple for you guys i expect but im at a loss as all search functions use mySQL in addition. Many thanks for your help in advance! Regards, Matt.
hello everyone. i'm having problem to create a search page. i want to create a search page like this but i dont have the coding source to refer.. can anyone give me the coding for me to refer.... Help Please i have a html page which is derived from an excel spreedsheet. is it possable to use php to search the page and pull a row of data from it and store them as $vars ? sort of treat it as a database. if so can you point me in the right direction. i tryed google with no luck. cheers Hi, I have a website which displays products on product display pages and static pages such as 'contact us'. I am now looking to add a search function which directs to the display page so the products are neatly presented. However, all the tutorials I can find are based on displaying the echo on same page as the search and directing the search to another page. Does anyone know how to do this? How can I write a 404 file to redirected any 'not found' page with structure of example.com/something/more/final.html to example.com/search?q=something+more+final Thanks 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'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 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> |