PHP - Tutorial For Creating A 'search Engine' With Multiple Word Search
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 Similar TutorialsI 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? 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 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 Hey All, I'm trying to add multiple word search to my site and I'm getting the following error: "mysql_num_rows(): supplied argument is not a valid MySQL result resource " I know, my search is posting because I'm getting my search terms back with the "nothing found" message I have set up. Here's what I have: Code: [Select] $search = $_POST["search"]; $arraySearch = explode(" ", $search); $arrayFields = array(0 => "title", 1 => "content"); $countSearch = count($arraySearch); $a = 0; $b = 0; $query = "SELECT * FROM table1 WHERE desc LIKE '$arraySearch'"; $countFields = count($arrayFields); while ($a < $countFields) { while ($b < $countSearch) { $query = $query."$arrayFields[$a] LIKE '%$arraySearch[$b]%'"; $b++; if ($b < $countSearch) { $query = $query." AND "; } } $b = 0; $a++; if ($a < $countFields) { $query = $query.") OR ("; } } $query = $query.")"; $query_result = mysql_query($query); if(mysql_num_rows($query_result) < 1) { echo '<p>No matches found for "'.$search.'"</p>'; } else { Print "<table border cellpadding=3>"; while($row = mysql_fetch_assoc($query_result)) { Print "<th>Description:</th> <td>".$row['desc']. "</td> "; } Print "</table> "; } You guys are the best, thanks so much. 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 found this amazing tutorial and i try to change it for a different database, but when i do a search it never finds anything. <?php $dbHost = 'localhost'; // localhost will be used in most cases // set these to your mysql database username and password. $dbUser = 'root'; $dbPass = '123'; $dbDatabase = 'ergasia2'; // 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[] = "Ο όρος αναζήτησις πρέπει να είναι έχει περισσότερους από 3 χαρακτήρες."; }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 Fname, Surname, StreetName, status FROM EMPLOYEES WHERE "; // grab the search types. $types = array(); $types[] = isset($_GET['Fname'])?"`Fname` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['Surname'])?"`Surname` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['StreetName'])?"`StreetName` LIKE '%{$searchTermDB}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) $types[] = "`sbody` 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 `stitle`"; // 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['stitle']}<br />{$row['sdescription']}<br />{$row['sbody']}<br /><br />"; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?> <html> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>My Simple Search Form</title> <style type="text/css"> #error { color: red; } </style> <body> <?php echo (count($error) > 0)?"The following had errors:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?> <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm"> Search For: <input type="text" name="search" value="<?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?>" /><br /> Search In:<br /> Body: <input type="checkbox" name="body" value="on" <?php echo isset($_GET['body'])?"checked":''; ?> /> | Title: <input type="checkbox" name="title" value="on" <?php echo isset($_GET['title'])?"checked":''; ?> /> | Description: <input type="checkbox" name="desc" value="on" <?php echo isset($_GET['desc'])?"checked":''; ?> /><br /> Match All Selected Fields? <input type="checkbox" name="matchall" value="on" <?php echo isset($_GET['matchall'])?"checked":''; ?><br /><br /> <input type="submit" name="submit" value="Search!" /> </form> <?php echo (count($results) > 0)?"Your search term: {$searchTerms} returned:<br /><br />" . implode("", $results):""; ?> </body> </html> The table which i use is the following ---------------- |EMPLOYEES| ---------------- |ssn | ---------------- |Fname ---------------- |postal code | ---------------- |salary | ---------------- |street name| ---------------- |street number | ------------------- |surname | ----------------- |UnionMembershipNumber| --------------------------------- |password | ----------------- |status | ---------------- Hello, I'm making a website which includes an articles page. I want users to be able to search for particular articles. For this search function I used the Simple SQL Search tutorial from phpfreaks (http://www.phpfreaks.com/tutorial/simple-sql-search). It's working quite well but i'd like to expand it a little. The most important thing i want changed is what happens when users enters a string which holds multiple words. The function from the tutorial perceives these words as one string and searches for that string as a whole. For example when a user enters 'winter 2012' and an article holds the string 'winter of 2012', the function returns no matches. This is, ofcourse, not the way i'd like it to function. I've managed to seperate the words and search for them individually by using explode and foreach, but now i'm getting duplicate results when an article holds mulitple words from the users' entry string. My idea to fix this was to make an array with the article id's of the articles that have matched, and then to exclude them from the SQL query for the next word from the search string by using 'NOT IN $array' in the where clause. Unfortunately i haven't managed to succeed with this so far and that's why i ask for your help.. This my search function: Code: [Select] function zoekopdracht() { require('dbcon.php'); $zoekopdr = trim($_GET['zzoek']); $zoekopdr = strip_tags($zoekopdr); if (strlen($zoekopdr) < 3) { echo "De zoekopdr moet minimaal 3 karakters bevatten."; } else { $zoekopdr = explode(" ", $zoekopdr); foreach($zoekopdr as $zoekterm) { $zoekopdrDB = mysql_real_escape_string($zoekterm); $searchSQL = "SELECT * FROM n_artikelen WHERE "; $types = array(); $types[] = isset($_GET['zartikel'])?" volledig_artikel LIKE '%{$zoekopdrDB}%'":''; $types[] = isset($_GET['ztitel'])?" titel LIKE '%{$zoekopdrDB}%'":''; $types[] = isset($_GET['zjaar'])?" YEAR(publicatie) LIKE '%{$zoekopdrDB}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) { $types[] = "volledig_artikel LIKE '%{$zoekopdrDB}%'"; // use the artikel + titel as a default search if none are checked $types[] = "titel LIKE '%{$zoekopdrDB}%'"; } $searchSQL .= implode(" OR ", $types) . " ORDER BY publicatie LIMIT 0,10"; $searchResult = mysql_query($searchSQL) or die(mysql_error()); if (mysql_num_rows($searchResult) < 1) { echo "De zoekopdracht '{$zoekopdr}' heeft geen resultaten."; } else { while ($row = mysql_fetch_array($searchResult, MYSQL_NUM)) { artikelelement($row); // function that outputs the result of $row[] } } } } } Additionally, if this problem is fixed, i'd love to see a way to sort the results on closest match (article which matches two words > article which matches one word). Thanks! I thinking about building a search engine just as a fun project and a way to develop my skills. However I'm not sure where to start... I want it to be a comparison search engine for computer parts so say the user type in "RAM" it would display results from PC World, Ebuyer, etc. I was thinking of using cURL but how do I know where the search results are on each page. For example say I get a html page of results from PC World and store them in a variable how do I then know what to strip out to get the results I want? Would I just have to look at the source code? Also would I then have to work this out for each site I wanted to search from and have a different method of getting the results from search site? If anyone has done anything like this in the past and could give me some advice that would be great. Thanks Hi, I have a script which searches the MySQL database. It outputs the result which is a business name, but I need the business name to be in a link so the user can click on it and go to another page to find out more information. However the business name is not included in the link, but the $value is.
Here is my script
<?php include 'init.php'; // normal search $result_tb = ""; if (!empty($_POST['SEARCH']) && !empty($_POST['search_value'])) { $e = $_POST['search_value']; $query = 'SELECT aquaticCenterName FROM reviews WHERE ' . "aquaticCenterName LIKE '%$e%' OR " . "town LIKE '%$e%' OR " . "county LIKE '%$e%' OR " . "country LIKE '%$e%' OR " . "rating LIKE '%$e%' "; $query_result = $con->query($query); $result_tb = '<div>'; while ($rows = $query_result->fetch_assoc()) { foreach ($rows as $k => $v) { $result_tb .= '<a href="reviewResults.php?aquaticCenterName= . $v . ">' . $v . '</a><br>'; } } $result_tb .='</div><hr>'; $con->close(); } ?> <?php include 'includes/overall/header.php'; include 'includes/logo.php'; ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table> <tr> <td> <input type="text" name="search_value" size="30" maxlength="30"/> </td> <td> <input type="submit" name="SEARCH" value="Search"/> </td> </tr> </table> </form> <?php echo $result_tb; ?> <?php include 'includes/overall/footer.php';But when I click on the link, I get this in the address bar reviewResults.php?aquaticCenterName=%20.%20$v%20. How do I get this to read eg, reviewResults.php?aquaticCenterName=PaulsAquaticCenter Many Thanks aquaman I have a search bar that searches my databases for information. It works perfectly on my site,. I want to know how to make it modular so that other people can place my search box on their site and get results from my databse without having to give out all my site infomration. Php search engine for my site I have a Romanian based language site: http://www.firmelavedere.com with informations about business companies. I implemented a simple php search engine for my website on pages like this on the top right corner: http://www.firmelave...aj-Zalau-15.php I want to add a new radio box field to select language for displayed text. Is there a possibility to integrate Google Site Search with more languages? How can i do that? I need some code suggestions, to make this script run fast. Thanks all. Hi Everyone. Am about to create a search engine for my project using php and mysql. My question is that > Do i have to keep creating tables and entries in the database to contain all the topics to be searched for? Or is there another way to go about it? cos i dont think i can really enter all the search topics and their web address and also their keywords. Thank You. I'm in the process of build a network and need to create a search that lets people search by both first and last names. I have tailored the code below to search for first names, but I don't know how to tailor it to search for both first and last names. Code: [Select] <?php //get data $button = $_GET['search']; $search = $_GET['search']; if (!$button) echo "You didn't submit a keyword."; else { if (strlen($search)<1) echo "Search term too short."; else { echo "You searched for $search<hr>"; require('connect.php'); //explode our search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //contruct query $x++; if ($x==1) $construct .= "firstname LIKE '%$search_each%'"; else $construct .= " OR firstname LIKE '%$search_each%'"; } //echo out construct $construct = "SELECT * FROM users WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if($foundnum==0) echo "No results found!<p>"; else { echo "$foundnum results found!<p>"; while ($runrows = mysql_fetch_assoc($run)) { //get data $firstname = $runrows['firstname']; $lastname = $runrows['lastname']; echo " $firstname $lastname "; } } } } ?> Can someone help me with my code. Used a tutorial as aid but still struggling. Basically I have a table called student. I created a search engine so that if a user searches for either the sname,fname or sno of a student then that student would appear. Apart from some notices I got it working and displaying students when searching for only their sname. Now, I want to be able to make it possible to find a student by searching either sname,fname or sno and I'm getting errors. Can anyone have a look at my code: Code: [Select] <?php //get data $button = $_GET ['submit']; $search = $_GET ['search']; if (!$button) echo "You didn't submit a term."; else { if (strlen($search)<=0) echo "search term too short."; else { echo "You searched for <b>$search</b><hr size='1'>"; include 'includes/config.php'; include 'includes/functions.php'; connect(); //explode search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; //Line 30 if ($x==1) $construct .= "sname,fname,sno LIKE '%$search_each%'"; //Line 32 else $construct .= "OR sname,fname,sno LIKE '%$search_each%'"; } $construct = "SELECT * FROM student WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); //Line 44 if ($foundnum==0) echo "No results found."; else { echo"$foundnum results found!<p>"; while ($runrows = mysql_fetch_assoc($run)) { //get data $sname = $runrows['sname']; $fname = $runrows['title']; $sno = $runrows['sno']; echo " <b>$fname</b> $sname $sno"; } } } } ?> Errors:Notice: Undefined variable: x in C:\Program Files\EasyPHP-5.3.3\www\Project\search.php on line 30 Notice: Undefined variable: construct in C:\Program Files\EasyPHP-5.3.3\www\Project\search.php on line 32 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Program Files\EasyPHP-5.3.3\www\Project\search.php on line 44 No results found. First time attempting this, so any tips on what I did wrong would be great. Thank you in advance. Hi, Im trying to do a search engine. However, im facing this errors.. Anyone can help.. Error : Notice: Undefined variable: searching in C:\wamp\www\i-document\s.php on line 17 Thankz in advance. Code: [Select] <h2>Search Form</h2> <form name="search" method="post" action="s.php"> Seach for: <input type="text" name="find" /> in <Select NAME="field"> <Option VALUE="file_name">File Name</option> <Option VALUE="year">Year</option> <Option VALUE="downer">Owner</option> < </Select> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </form> <?php if ($searching =="yes"){ echo "<h3>Search Results</h3><p>"; if ($find == ""){ echo "<p>Please Enter a search term"; exit; } include "config.php"; $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); $query = mysql_query("SELECT * FROM document WHERE upper($field) LIKE'%$find%'"); while($result = mysql_fetch_array($query)){ echo $result['file_ref']; echo " "; echo $result['file_name']; echo "<br>"; echo $result['owner']; echo "<br>"; echo "<br>"; } $matches=mysql_num_rows($query); if ($matches == 0){ echo "Sorry, we can not find an entry to match your query<br><br>"; } echo "<b>Searched For:</b> " .$find; } ?> I made a search engine to search my database for specific users ( well I used a tutorial ). I'm not getting any errors atleast when loading the page which is a first for me. However, now I am tackled by something new. When entering the keywords and submitting the search I get: Access forbidden! You don't have permission to access the requested object. It is either read-protected or not readable by the server. If you think this is a server error, please contact the webmaster. Error 403 127.0.0.1 04/30/07 11:09:21 Apache/2.2.16 (Win32) PHP/5.3.3 Which is odd for me because I am using the same config.php with connection code to connect to the db which I used with all my other pages. And in those pages I have been able to add/delete/edit and display records from the database tables. Does this have something to do with it being a search engine? Here is my code: Code: [Select] <html> <head> </head> <body> <h2>Search</h2> <form name="search" method="post" action="<?=$PHP_SELF?>"> Seach for: <input type="text" name="find" /> in <Select NAME="field"> <Option VALUE="fname">First Name</option> <Option VALUE="sname">Last Name</option> <Option VALUE="sno">Profile</option> </Select> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </form> </body> </html> <?php //This is only displayed if they have submitted the form $searching ='searching'; if ($searching =="yes") { echo "<h2>Results</h2><p>"; //If they did not enter data then they receive an error if ($find == "") { echo "<p>You forgot to enter a search term"; exit; } // Otherwise connect to database include 'includes/config.php'; include 'includes/functions.php'; connect(); // filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); // search for term in specified field $data = mysql_query("SELECT * FROM student WHERE upper($field) LIKE'%$find%'"); // display results while($result = mysql_fetch_array( $data )) { echo $result['fname']; echo " "; echo $result['sname']; echo "<br>"; echo $result['sno']; echo "<br>"; echo "<br>"; } //Counts number or results and display message if there we're non $anymatches=mysql_num_rows($data); 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; } ?> Any ideas? Thanks in advance Can anyone please help me with my code. I would like to display the data from another column instead of the id in the url generated by the scirpt. Code: [Select] <?php include('/home/arts/public_html/shows/includes/config.db.php'); if ($link){ $rpp = 10; // results per page $adjacents = 4; $page = intval($_GET["page"]); if(!$page) $page = 1; $reload = $_SERVER['PHP_SELF']; $sql = "select * from craft_shows WHERE venue_state='MD' order by start_date "; $result = mysql_query($sql) or die(mysql_error()); // count total number of appropriate listings: $tcount = mysql_num_rows($result); $date = strftime("%b %d, %Y", strtotime($row['start_date'])); echo "<table class='table7' width='100%' cellpadding='5' cellspacing='1'>"; echo "<tr><td> </td><td>Date</td><td>City</td><td>Show Name</td><td>Attendance</td></tr>"; echo "<tr><td colspan='7'><hr></td></tr>"; // count number of pages: $tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number $date = strftime("%b %d, %Y", strtotime($row['start_date'])); $count = 0; $i = ($page-1)*$rpp; while(($count<$rpp) && ($i<$tcount)) { mysql_data_seek($result,$i); $row = mysql_fetch_array($result); $id = $row['id']; echo "<tr><td>"; echo "<a href=\"/show_submits/show_detail.php?id=$id\">Details</a>"; echo "</td><td>"; echo strftime('%b %d, %Y', strtotime($row['start_date'])); echo "</td><td>"; echo $row['venue_city']; echo "</td><td>"; echo $row['show_name']; echo "</td><td>"; echo $row['num_visitors']; echo "</td></tr>"; $i++; $count++; } echo "</table>"; echo "<br>"; // call pagination function: include("pagination1.php"); echo paginate_one($reload, $page, $tpages, $adjacents); } ?> This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=322620.0 Hi, I'm having two issues with my Search engine for my website. It is created to search through my database (it doesn't crawl through pages). The first problem I'm having is when I type in for example: Super Mario Bros and there is a row in my table with a field called Super Mario Brothers this row is not included as a successful result to the search. I need to somehow modify my code to search every word in every table cell in the database. So another example. I have 5 rows, each with one cell, named as follows: One Two Three Four Five If I was to type in the search box: One Two Three Four Five it should display all rows (it obviously doesn't do that right now lol) The second issue has to do with my sql query. It looks like this: $query = "select * from sheets where artist like \"%$trimmed%\" OR title like \"%$trimmed%\" order by artist"; $numresults=mysql_query($query); I need this query to search in the columns artist and title (like it is doing above) AS WELL as search only those rows that have an active status set to 'yes'. I tried to type something like: $query = "select * from sheets where active='yes' && artist like \"%$trimmed%\" OR title like \"%$trimmed%\" order by artist"; but this obviously causes problems. How do i require the query to include rows that are active, but have it look through artist OR title as well? Here is my code below. Any insight appreciated. Will be working on it til someone is available. Thanks <?php include_once('inc/functions.php'); // Get the search variable from URL $var = @mysql_safe($_GET['q']) ; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=10000; // check for an empty string and display a message. if ($trimmed == "") { $error = "<tr><td colspan='2' style='text-align: center; border-style: solid; border-color: #f43636; background-color: #fe6a6a;'><strong>Type In A Sheet To Search For</strong></td></tr>"; } // check for a search parameter if (!isset($var)) { $error = "<tr><td colspan='2' style='text-align: center; border-style: solid; border-color: #f43636; background-color: #fe6a6a;'><strong>Type In A Sheet To Search For</strong></td></tr>"; } // Build SQL Query $query = "select * from sheets where artist like \"%$trimmed%\" OR title like \"%$trimmed%\" order by artist"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results if ($numrows == 0) { // If search was not found $error = "<tr><td colspan='2' style='text-align: center; border-style: solid; border-color: #f43636; background-color: #fe6a6a;'><strong>Unfortunately that sheet was not found, however, please request it by clicking below</strong></td></tr><tr><td colspan='2' style='text-align: center; border-left-style: solid; border-bottom-style: solid; border-right-style: solid; border-color: #f43636; background-color: #f5f5f5;'><a href='request.php'>Request A Sheet Here</a></td></tr>"; } // 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"); $search = " "; $break = "<br />"; if($var!=""){ $search = "Search:"; $break = ""; } ?> <br /><div id='headsearch'></div> <div style="width: 210px; margin-left: auto; margin-right: auto; text-align: center;"> <form name="form" action="search.php" method="get"> <div style="float: left;"><input type="text" name="q" /></div> <div style="float: right;"><input type="image" src="img/search.png" alt="Search" name="Submit" value="Search" /></div> </form> </div> <?php // display what the person searched for echo "<center><div style='width: 210px; margin-left: auto; margin-right: auto; text-align: center;'>$search <span style='color: #6aa504; margin-left; auto; margin-right: auto;'>" . stripslashes($var) . "</span></div></center>"; ?> <?php // begin to show results set $count = 1 + $s ; $greenboxleft = "greenboxleft"; $greenboxright = "greenboxright"; $grayboxleft = "grayboxleft"; $grayboxright = "grayboxright"; $colorvalue = 0; echo "$break<table width='700px' align='center' style='border-collapse:separate; border-spacing:0px;'><th style='background-color: #93DB70; border-bottom-style: solid; border-color: #6aa504;'>Artist</th><th style='background-color: #93DB70; border-bottom-style: solid; border-color: #6aa504;'>Title</th>"; if($error==""){ // now you can display the results returned while ($row= mysql_fetch_array($result)) { $artist = $row["artist"]; $title = $row["title"]; if(($colorvalue%2)==0){ $styleleft = $greenboxleft; $styleright = $greenboxright; } else{ $styleleft = $grayboxleft; $styleright = $grayboxright; } echo "<tr>"; echo "<td align='center' width='350px' id='$styleleft'><div id='songsboxleft'><strong>". ucwords($row['artist']). "</strong></div></td>"; echo "<td align='center' width='350px' id='$styleright'><div id='songsboxright'><a target='_blank' name='downloadclick' href='download.php?sheet=".$row['url']."&artist=".$row['artist']."&title=".$row['title']."'>" .ucwords($row['title']). "</a></div></td>"; echo "</tr>"; $colorvalue++; } } else{ echo $error; } echo "</table>"; ?> |