PHP - Mysql Database Search Engine On Username??
Hi,
I'm am trying to use a search engine that search's for a username in the database and displays the information back. I have searched for a script but none of them has helped me. I have tried to use this without any luck: mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db("dbsystem") or die(mysql_error()); $todo=$_POST['todo']; if(isset($todo) and $todo=="search"){ $search_text=$_POST['search_text']; $type=$_POST['type']; $search_text=ltrim($search_text); $search_text=rtrim($search_text); if($type<>"any"){ $query="select * from users where name = '$search_text'"; }else{ $kt=split(" ",$search_text);//Breaking the string to array of words // Now let us generate the sql while(list($key,$val)=each($kt)){ if($val<>" " and strlen($val) > 0){$q .= " name like '%$val%' or ";} }// end of while $q=substr($q,0,(strlen($q)-3)); // this will remove the last or from the string. $query="select * from users where $q "; } // end of if else based on type value echo $query; echo "<br><br>"; $nt=mysql_query($query); echo mysql_error(); while($row=mysql_fetch_array($nt)){ echo "$row[name]<br>"; } // End if form submitted }else{ echo "<form method='post' action=''><input type='hidden' name='todo' value='search' /> <input type='text' name='search_text' /><input type='submit' value='Search' /><br> <input type='radio' name='type' value='any' checked />Match any where <input type='radio' name='type' value='exact' />Exact Match </form> "; } I will be grateful if you can help with this. Similar TutorialsThis topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=326179.0 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! 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 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, so i made table with Tags row which is Text(126).. and idea is to put text like "PHP, MySQL, Forum, Blog" etc etc...
I have problem searching tags my search code:
$requestedtag = $con->real_escape_string($_GET['tag']); $sql = "SELECT * FROM images WHERE tags = '$requestedtag' ORDER BY ID DESC LIMIT 12"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $image_id = $row["ID"]; $image_title = $row["Title"]; $image_url = $row["ImgURL"]; $image_tags = $row["Tags"]; echo '<div class="col-3"><div class="thumb"><a href="/image.php?id='.$image_id.'" title="'.$image_title.'"><img src="'.$image_url.'"></img></a></div></div>'; } } But it doesnt return anything. I think the problem is that row["Tags"]; is divided by "," from tags and i should split it somehow but i dont really know what to do... Hi. I have a database named 'Forums' with a table named 'forumlist'. The fields in the table are 'id', 'name', 'link', and 'keys'. I am trying to search the database in either the 'name' or 'keys' field and display the matches. I am getting this error: Parse error: syntax error, unexpected T_STRING, expecting ']' in C:\xampp\htdocs\search3.php on line 51 (The define fields) <html> <head> <title>My Forum Search</title> <style type="text/css"> table { background-color: #CCC } th { width: 150px; text-align: left; } </style> </head> <body> <h1>Forum Search</h1> <form method="post" action="search3.php"> <input type="hidden" name="submitted" value="true" /> <label>Search Category: <select name="category"> <option value="keys">Keyword</option> <option value="name">Name</option> </select> </label> <label><input type="text" name="criteria" /></label> <input type="submit" /> </form> <?php if (isset($_POST['submitted])) { DEFINE ('DB_USER', 'root'); DEFINE ('DB_PSWD', '******'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'Forums'); $dbcon = mysqli_connect(DB_HOST, DB_USER, DB_PSWD, DB_NAME); $category = $_POST['category']; $criteria = $_POST['criteria']; $query = "SELECT * FROM forumlist WHERE $category LIKE '$criteria'"; $result = mysqli_query($dbcon, $query) or die ('Error retrieving data') echo "<table>"; echo "<tr> <th>Name</th><th>Link</th> </tr>"; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { echo "<tr><td>"; echo $row['name']; echo "</td><td>"; echo $row['link']; echo "</td></tr>"; } echo "</table>"; } // end of main if state ?> </body> </html> Thanks in advance I'm using some code to create a select menu of a fieldname of data I have in a mysql database : Code: [Select] <?php mysql_connect('localhost' , 'dbname', 'password'); mysql_select_db('dbname'); $result=mysql_query("SELECT * FROM Persons"); if(mysql_num_rows($result)>0) { ?> <select name="Persons"> <?php while($rows=mysql_fetch_array($result)){ ?> <option value="<?php echo $rows['id']; ?>"> <?php echo $rows['FirstName']; ?></option> <?php } ?> </select> What I would like to do is to elevate this into a jump menu form so that if the user selects an item from my form they are taken to a results page showing the full row of data from the database. Basically a search form containing items from the database they can choose to see more details on. eg. In my example you select a persons name and then you are taken to a results page which displays the details of that person from the database. Problem is I don't know how to do this and have been trawling around for a couple of days to find a solution (sorry I'm new to php). I would appreciate some help or a working example would be great of : 1/ A working dynamic jump menu 2/ The page that would process the form 3/ The results page displaying the data I have selected. Thank you for your time... I have a search set up to search a table for the text entered in a textbox, I have two columns in the table, one with the first name of people, and the second with their last names, I am wondering how I can search both, so for instance: I type in the search field: Roger Smith in the database it would look like: First_name-----|-----Last_name -------------------|------------------- Roger------------|-------Smith my current query is: Code: [Select] $query = mysql_query("SELECT * FROM users WHERE fname LIKE '%$find%' OR lname LIKE '%$find%'"); But if I type both parts of the name it doesn't return anything. works fine if I just search for "Roger" OR "Smith". Say a user puts in a support request, and for every request it generates a unqiue string, and enters it into the database. Ok, now say there is a text field, when the user enters their unique string and it finds a match, it displays the data along with it. How can I accomplish this? Im kind of new to mysql, but I know basic SQL. Would be great if somebody could point me in the right direction! Thanks This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=326703.0 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 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 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. I need some help with a php code I made for a search engine which I will use on my site, but an error code comes up please help me im ok at php but i need some pointers on my code! CODE: Code: [Select] <?php $button = $GET_['submit']; $search = $GET_['search']; if (!$button) echo "Please enter a keyword!"; else { if (strlen($search)<2) echo "search term to short" else { echo "you searched for $search <hr size='1'>" } mysql_connect("ftp.gpcoin.monkeyserve.com","seanhall_seanhall","81834567"); mysql_select_db("seanhall_search"); $search_exploded = explode(" ",$search) foreach($search_exploded as $search_each) { $x++; if ($x==1) $construct .= "keywords LIKE '%$search_each%'"; else $construct .= " OR keywords LIKE '%$search_each%'"; } $construct = "SELECT * FROM searchengine WHERE $construct"; echo $construct; $run = mysql_query($construct); $found = mysql_num_rows($run) if ($found==0) echo "No results Found."; else { echo "$foundnum results found!<p>"; while ($runrows = mysql_fetch_assoc($run)) { $title = $runrows['title']; $desc = $runrows['description']; $url = $runrows['url'] echo " <b>$title</b><br> $desc<br> <a herf='$url'>$url</a><br> "; } } } ?> error: Parse error: syntax error, unexpected T_ELSE, expecting ',' or ';' in /home/seanhall/public_html/search.php on line 11 Help 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>"; ?> Ok, I have the code below and it only searches one keyword of my database please could you tell me how I can search multiple keywords? <? /* * search.php * * Script for searching a datbase populated with keywords by the * populate.php-script. */ print "<html><head><title>[Squashy] Search! NOT MESSED UP.</title></head><body>\n"; if( $_POST['keyword'] ) { /* Connect to the database: */ mysql_pconnect("mysql3.000webhost.com","a4580813_dba","censored") or die("ERROR: Could not connect to database!"); mysql_select_db("a4580813_db"); /* Get timestamp before executing the query: */ $start_time = getmicrotime(); /* Execute the query that performs the actual search in the DB: */ $result = mysql_query(" SELECT p.page_url AS url, COUNT(*) AS occurrences FROM page p, word w, occurrence o WHERE p.page_id = o.page_id AND w.word_id = o.word_id AND w.word_word = \"".$_POST['keyword']."\" GROUP BY p.page_id ORDER BY occurrences DESC LIMIT ".$_POST['results'] ); /* Get timestamp when the query is finished: */ $end_time = getmicrotime(); /* Present the search-results: */ print "<h2>[Squashy] Search Results For '".$_POST['keyword']."':</h2>\n"; for( $i = 1; $row = mysql_fetch_array($result); $i++ ) { print "$i. <a href='".$row['url']."'>".$row['url']."</a>\n"; print "(occurrences: ".$row['occurrences'].")<br><br>\n"; } /* Present how long it took the execute the query: */ print "This search took: ".(substr($end_time-$start_time,0,5))." seconds."; } else { /* If no keyword is defined, present the search-page instead: */ print "<form method='post'>[Squashy Search] <input type='text' size='20' name='keyword'>\n"; print "Results: <select name='results'><option value='5'>5</option>\n"; print "<option value='10'>10</option><option value='15'>15</option>\n"; print "<option value='20'>20</option></select>\n"; print "<input type='submit' value='Search [Squashy]'></form>\n"; } print "</body></html>\n"; /* Simple function for retrieving the currenct timestamp in microseconds: */ function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } ?> Thanks Please help Soon! |