PHP - Search Script With Several Options
Hello PHPFreaks,
I am busy with creating a search script that will search the database. I got it working so far but i want it to search for not only one thing but several things so actually make options in the form that you you choose only to search on name or only on address. How do i do this? The PHP code: Code: [Select] <?php mysql_connect ("localhost", "username","password") or die (mysql_error()); mysql_select_db ("database table"); $term = $_POST['term']; $sql = mysql_query("select * from databasetable where naam like '%$term%'"); while ($row = mysql_fetch_array($sql)){ echo "<center>"; echo "<table width='600px'>"; echo "<tr>"; echo "<td><b>Naam:</b> </td><td>".$row['naam']; echo "</td><td><b>Telefoon:</b> </td><td>".$row['telefoon']; echo "</td></tr><tr>"; echo "<tr>"; echo "<td><b>Adres:</b> </td><td>".$row['adres']; echo "</td><td><b>Mobiel:</b> </td><td>".$row['mobiel']; echo "</td></tr><tr>"; echo "<tr>"; echo "<td><b>Postcode:</b> </td><td>".$row['postcode']; echo "</td><td><b>E-mail:</b> </td><td>".$row['email']; echo "</td></tr><tr>"; echo "<tr>"; echo "<td><b>Woonplaats:</b> </td><td>".$row['woonplaats']; echo "</td></tr>"; echo "</table>"; echo "<br /><br />"; echo "<table width='400px'>"; echo "<tr>"; echo "<td><b>Datum:</b> </td><td>".$row['datum']; echo "</td></tr><tr><td><b>Probleem:</b> </td><td>".$row['probleem']; echo "</td></tr><tr>"; echo "<td><b>Mogelijke oplossing:</b> </td><td>".$row['oplossing1']; echo "</td></tr><tr><td><b>Oplossing:</b> </td><td>".$row['oplossing2']; echo "</td></tr><tr>"; echo "<td><b>Wachtwoord:</b> </td><td>".$row['wachtwoord']; echo "</td><tr><td><b>Geschatte Prijs:</b> </td><td>".$row['prijs']; echo "</td></tr><tr>"; echo "<td><b>Bijgeleverd:</b> </td><td>".$row['bijgeleverd']; echo "</td></tr>"; echo "</table><br />"; echo "---------------------------------------------------------------------------------------"; echo "</center>"; echo "<br/><br/>"; } ?> HTML Form: Code: [Select] <form action="search.php" method="post"> <b>RMA Zoeken:</b><br /> <input type="text" name="term" /><br /><br /> <input type="submit" class="art-button" name="submit" value="Submit" /> </form> Similar TutorialsHello All, Hi I have this serach function, wich searches on site by a lot of parameters at the same time (titolo, titolo2, attore1,etc...) , but I want to make them options, so you would have a search field and an options dropdown menu. Can anyone help me with this? My code follows: PHP Code: [Select] function jm_search(){ global $database, $sstring, $my, $cinConfig, $Itemid, $option, $mainframe; $tl_title = _JMOVIES_SEARCHRESULT." ".$sstring; $suchstring = trim( strtolower( $sstring ) ); $query1 = "SELECT * FROM #__jmovies WHERE" ."\n (titolo LIKE '%".$suchstring."%'" ."\n OR titolo2 LIKE '%".$suchstring."%'" ."\n OR attore1 LIKE '%".$suchstring."%'" ."\n OR attore2 LIKE '%".$suchstring."%'" ."\n OR attore3 LIKE '%".$suchstring."%'" ."\n OR attore4 LIKE '%".$suchstring."%'" ."\n OR nazione LIKE '%".$suchstring."%'" ."\n OR regista LIKE '%".$suchstring."%'" ."\n OR descrizione LIKE '%".$suchstring."%'" ."\n OR anno LIKE '%".$suchstring."%') AND published = 1 AND access <= ".(int)$my->gid." ORDER BY titolo"; $database->setQuery($query1); //echo $database->getQuery(); $rows = $database->loadObjectList(); if(is_file($mainframe->getCfg('absolute_path')."/components/".$option."/templates/".$cinConfig['template']."/show_search_tpl.php")) require($mainframe->getCfg('absolute_path')."/components/".$option."/templates/".$cinConfig['template']."/show_search_tpl.php"); else require($mainframe->getCfg('absolute_path')."/components/".$option."/templates/default/show_search_tpl.php"); } HTML Code: [Select] <td width="44%" valign="middle" bgcolor="#eeeeee" style="text-align:right"> <input name="sstring" type="text" class="jmoviesInputSearch" title="<?php echo _JMOVIES_SEARCH?>" onfocus="if(this.value=='<?php echo _JMOVIES_SEARCH?>') this.value='';" onblur="if(this.value=='') this.value='<?php echo _JMOVIES_SEARCH?>';" onchange="javascript:document.jmoviesSearchForm.submit();" value="<?php echo _JMOVIES_SEARCH?>" size="50"/><input type="submit" value="OK" class="button"/></td> Thank you. 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 When I open the page in browser it list everything that's in my DB without searching for anything. What is wrong to make it do this? Code: [Select] <form method="post" action="<?=$PHP_SELF?>"> <center> <table border="0" cellpadding="0" width="100%"> <tr> <td width="30%"> <p align="right">Search For GID Number:</p></td> <td width="80%"><input type="text" name="searchterm"></td> </tr> </table> </center> <p align="left"> <input type="submit" value="Search"><br><br> </form> <?php include('fbvar.php'); /*set varibles from form */ $searchterm = $_POST['searchterm']; trim ($searchterm); /*check if search term was entered*/ if (!$searchterm){ echo 'Please enter a search term.'; } /*add slashes to search term (')(")*/ if (!get_magic_quotes_gpc()) { $searchterm = addslashes($searchterm); } /* connects to database*/ @ $dbconn = new mysqli($databaseserver, $databaseuser, $databasepass, $databasename); if (mysqli_connect_errno()) { echo 'Error: Could not connect to database. Please try again later.'; exit; } /*query the database*/ $query = "SELECT gid, gift FROM $gifts WHERE gift like '%".$searchterm."%' ORDER BY gid"; $result = $dbconn->query($query); /*number of rows found*/ $num_results = $result->num_rows; echo '<p>Found: '.$num_results.'</p>'; /*loops through results*/ for ($i=0; $i <$num_results; $i++) { $num_found = $i + 1; $row = $result->fetch_assoc(); echo "$num_found. ".($row['gid']).' '.($row['gift'])." <br />"; } /*free database*/ $dbconn->close(); //End of the Search Database form ?> I would like to edit this script's SQL query to SELECT FROM multiple tables within my database. Can this be done first of all and what would i need to change? here's the script: Code: [Select] <?php // Get the search variable from URL $var = @$_GET['q'] ; $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 ** EDIT REQUIRED HERE ** mysql_connect("host","username","password"); //(host, username, password) //specify database ** EDIT REQUIRED HERE ** mysql_select_db("database name") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "select * from the_table where 1st_field like \"%$trimmed%\" order by 1st_field"; // 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 . ""</p>"; // begin to show results set echo "Results"; $count = 1 + $s ; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["1st_field"]; 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&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>"; ?> All i want it to do is search a field in 3 different tables in my database called "postcode" and return search results. Ive seen the JOIN feature but don't know how to use it, any help i would appreciate. Thank you. hello i need a script that sends data from the searchbar to a search.php and there the entries are displayed with the category someone knows how to write it or has someone an example https://prnt.sc/ujzvuf I am building a simple search engine script for my website which allows users to search for electronic devices that we have in our database. Here is the HTML code. Code: [Select] <form name="search" action="search.php" method="get"> <input type="text" name="query" size="50" /> <input type="submit" name="submit" value="Search" /> </form> Here is the PHP code. <?php error_reporting(0); include 'config.php'; mysql_connect("localhost", "root", "password") or die(mysql_error()); mysql_select_db("maindatabase") or die(mysql_error()); // get the data from the form $search_query = $_GET['query']; // mysql query $query = mysql_query("SELECT * FROM `products` WHERE productName LIKE '%$search_query%'"); $count_rows = mysql_num_rows($query); echo "Results found: " . $count_rows; ?> Here is the problem: Whenever I enter a single keyword in the search, the search brings some results. BUT, whenever I enter multiple keywords, the search brings 0 rows. For example: I have a product called Sony Bravia Television 42 inches - 1080p HD in my database. When type "sony" in the search and press the search button, I only get 1 row as the result. But when I enter "sony television" in the seach, I get 0 row results. Why is that? What can I do to fix this problem? I want to return results that contain all the keywords that the search query had. Just like any search engine: Google, Yahoo, etc. hi guys, i'm working for some time now on a project and i'm really struggeling with 1 part of the project. What is the input for the script? the input for the script are numbers(1234) or number - letter combinations (xtx-12-34). also important to know is that $_POST['ordernummer']; can hold multiple inputs divided by a "," (like 1234,9876,1597) Database setup. my sql database has data stored, these numbers or number - letter combinations are in 1 collum. there are (ofc) more collums. What do i need. I need the input to be ordered by customer_name. below i have pasted the script the i have atm. It only works with numbers, as soon as i start to add letters, it dies. After some asking around it turns out the query is wrong, but i have no clue how i'm gone get the data i need. hopefully, after reading the code, you'll understand i bit better what i need $Ordernummer = $_POST['ordernummer']; $allorders[0] = ""; $query1 = mysql_query("SELECT CUSTOMER_NAME,COMP_ULL_ORDER_NUM_DOSSIER_NUM,ORDER_EINDGEBRUIKER,CUSTOMER_SEGMENT FROM data WHERE COMP_ULL_ORDER_NUM_DOSSIER_NUM IN (".$Ordernummer.") GROUP BY CUSTOMER_NAME "); while(list($customer,$ordernr)= mysql_fetch_row($query1)){ $query2 = mysql_query("SELECT CUSTOMER_NAME,COMP_ULL_ORDER_NUM_DOSSIER_NUM,ADDRESS_INST_STREET,ADDRESS_INST_NUMBER,ADDRESS_INST_ZIPCODE,ADDRESS_INST_CITY,CUSTOMER_SEGMENT,ORDER_EINDGEBRUIKER FROM data WHERE CUSTOMER_NAME='$customer' AND COMP_ULL_ORDER_NUM_DOSSIER_NUM IN (".$Ordernummer.") ORDER BY CUSTOMER_NAME "); while(list($cust,$order,$street,$housenr,$zip,$city)=mysql_fetch_row($query2)){ $full_line = $order." - ".$street." ".$housenr.", ".$zip.", ".$city."<br>"; $allorders[0] .= $full_line; } echo "<br>Customer: ".$customer." <br> Location(s) impacted:<br> ".$allorders[0]. "<br>"; $allorders[0] = ""; } so, like i said, i know atm no safety is added (sql injection). and query1 is wrong (i'm told, but i get the results i need) hope you some can help me, any help is greatly appreciated thanks! nathan ps, sorry for the bas English, i'm not a native English speaker/writer I'm getting a blank screen when I run the following search script. The script should retrieve news entries from the db which contain the keyword and echo those entries with the keyword highlighted in yellow. Could anyone shed light on why the script isn't running as it should?... Thanks in advance if you can help. Code: [Select] <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { // form submitted if(!empty($_POST['keywords'])) { // search term has been entered $keywords = trim($_POST['keywords']); $search_exploded = explode(" ", $keywords); include('includes/mysqli_connect.php'); // connect to db // execute query $q = "SELECT title, subtitle, news_entry FROM news WHERE title LIKE '%$keywords%' OR subtitle LIKE '%$keywords%' OR news_entry LIKE '%$keywords%' "; $r = mysqli_query($dbc, $q); // If results were found, output them $retrieved = mysqli_num_rows($r); if (@mysqli_num_rows($r) > 0) { echo "<h3>" . $retrieved . ' result(s) found, as follows:</h3>'; while ($row = mysqli_fetch_array($r)) { echo "<div class='news_borders_top_bottom'>" . '<h1>' . $row['title'] = str_replace($_POST['keywords'], "<div class='highlight'>{$_POST['keywords']}</div>", $row['title']); . '</h1>' . '<h2>' . $row['subtitle'] = str_replace($_POST['keywords'], "<div class='highlight'>{$_POST['keywords']}</div>", $row['subtitle']); . '</h2>' . '<p>' . $row['news_entry'] = str_replace($_POST['keywords'], "<div class='highlight'>{$_POST['keywords']}</div>", $row['news_entry']); . '</p>' . '<div class="created_on">Created on: ' . $row['created'] . '</div></div>'; } mysqli_close($dbc); echo "<p><a href='search_archive.php'>Search again</a></p>"; ?> </div> </div> <?php include('includes/footer.php'); exit(); } else { // no matches echo "No news entries were found which matched your search criteria."; } } else { // no search term entered echo "Please enter a search term."; } } else { // search button not yet clicked so show form ?> <h1>Search News Archive</h1> <form method="post" action="search_archive.php" id="searchform"> <p><input type="text" id="keywords" name="keywords"> </p> <p><input type="submit" name="submit" value="Search!"> </p> </form> </div> </div> <?php } ?> I wrote this script to query the database and get the count between timestamps. I'm using strtotime to convert the user selected date and the pre-selected times into a usable timestamp to search with. I've echo the first one to ensure that it's creating the correct timestamp with time and it is. The problem is that it's returning data that's outside of the time. I don't know if it's my php or mysql, so I was hoping one of you could help. Thanks! Code: [Select] <?php /** * @author William Morris * @copyright 2010 */ include('inc/db.php'); $startdate = "2010-07-01"; $enddate = "2010-08-05"; echo "Start Date: ".$startdate."<br>"; echo "End Date: ".$enddate."<br>"; //convert dates into timestamp $startdate1 = strtotime($startdate."00:00:00"); $enddate1 = strtotime($enddate."11:59:59"); echo "Start Date 1: ".$startdate1."<br>"; echo "End Date 1: ".$enddate1."<br>"; //convert dates into morning timestamp $startdate1 = strtotime($startdate."06:00:00"); $enddate1 = strtotime($enddate."11:59:59"); $sql = mysqli_query($conn, "SELECT COUNT(event_time) FROM `event` WHERE event = 'Registration' AND event_time BETWEEN '$startdate1' AND '$enddate1'"); $row = mysqli_fetch_array($sql); //convert dates into afternoon timestamp $startdate2 = strtotime($startdate."12:00:00"); $enddate2 = strtotime($enddate."17:59:59"); $sql1 = mysqli_query($conn, "SELECT COUNT(event_time) FROM `event` WHERE event = 'Registration' AND event_time BETWEEN '$startdate2' AND '$enddate2'"); $row1 = mysqli_fetch_array($sql1); //convert dates into Evening timestamp $startdate3 = strtotime($startdate."18:00:00"); $enddate3 = strtotime($enddate."23:59:59"); $sql2 = mysqli_query($conn, "SELECT COUNT(event_time) FROM `event` WHERE event = 'Registration' AND event_time BETWEEN '$startdate3' AND '$enddate3'"); $row2 = mysqli_fetch_array($sql2); //convert dates into night timestamp $startdate4 = strtotime($startdate."00:00:00"); $enddate4 = strtotime($enddate."05:59:59"); $sql3 = mysqli_query($conn, "SELECT COUNT(event_time) FROM `event` WHERE event = 'Registration' AND event_time BETWEEN '$startdate4' AND '$enddate4'"); $row3 = mysqli_fetch_array($sql3); echo "<table width='50%' border='0'> <tr> <td bgcolor='#d3d3d3'><div align='center'>Morning (6am-12pm)</div></td> <td bgcolor='#d3d3d3'><div align='center'>Afternoon (12pm-6pm)</div></td> <td bgcolor='#d3d3d3'><div align='center'>Evening (6pm-12am)</div></td> <td bgcolor='#d3d3d3'><div align='center'>Night (12am-6am)</div></td> </tr>"; echo "<tr> <td><div align='center'>".$row['COUNT(event_time)']."</div></td> <td><div align='center'>".$row1['COUNT(event_time)']."</div></td> <td><div align='center'>".$row2['COUNT(event_time)']."</div></td> <td><div align='center'>".$row3['COUNT(event_time)']."</div></td> </tr>"; echo "</table>"; ?> Hello,can anyone help me create members search script?
here is image example
here is 'users 'table
`id` int(11) NOT NULL auto_increment, `age` varchar(200) collate utf8_unicode_ci NOT NULL, `city` varchar(200) collate utf8_unicode_ci NOT NULL, `username` varchar(30) collate utf8_unicode_ci NOT NULL, `password` varchar(150) collate utf8_unicode_ci NOT NULL, `salt` varchar(10) collate utf8_unicode_ci NOT NULL, `mgroup` int(3) NOT NULL, `email` varchar(100) collate utf8_unicode_ci NOT NULL, `ip` varchar(15) collate utf8_unicode_ci NOT NULL, `posts` int(11) NOT NULL, `date_joined` varchar(25) collate utf8_unicode_ci NOT NULL, `logged_in` int(1) NOT NULL default '0', `last_action_time` int(25) NOT NULL, `signature` text collate utf8_unicode_ci NOT NULL, `avatar` varchar(300) collate utf8_unicode_ci NOT NULL default 'default', `what_is_doing` varchar(30) collate utf8_unicode_ci NOT NULL, `what_is_doing_id` varchar(100) collate utf8_unicode_ci NOT NULL, `name` varchar(200) collate utf8_unicode_ci NOT NULL, `website` varchar(200) collate utf8_unicode_ci NOT NULL, `title` varchar(150) collate utf8_unicode_ci NOT NULL, `rank_pips` int(11) NOT NULL, `friends` tinytext collate utf8_unicode_ci NOT NULL, `blocks` tinytext collate utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;Please help me? Edited by sopranolv, 30 January 2015 - 05:26 AM. Hi guys,
What I'm trying to accomplish sounds like fairly easy task but due to my poor knowledge of php this turned to be quite a challenge.
What I'm trying to do is to make a php script that will search the keywords on the multiple websites.
Websites that I will search are all web shops, selling spare part for home appliances and keywords used are usually original spare part codes.
When searching, script is searching these websites using their own search functions and not Google or other search engines.
Input for this script should be a CSV file containing list of keywords and URLs of the web shops that needs to be search for all these keywords. Here is the example: http://prntscr.com/4ebhxh Script should perform like this: It picks up the 1st keyword, browse to the URL1, uses its search, searches for the product, if it finds it, copy its price and write it back to original input CSV. If it doesn't find match (search results appear empty) it should write "no match found" and continue to URL2, URL3 and so on... When all URLs from the list are checked for the 1st keyword, scripts picks up 2nd keyword and continues on through all these keywords are not checked. This would be a resulting CSV file after the 1st keyword is checked: http://prntscr.com/4ebj52 After all data from the input CSV file are processed, script should prompt a msg and create a download link for that CSV file to be downloaded. If there are multiple matches, in other words if for one keyword some of the website searches find 2 or more products, something like "More then one match" should be written in the file. Example: http://prntscr.com/4ebkcx Please note that non of the website is using SSL and non of them requires login in order to display the prizes. This fact should make this script easier to build. Its not important for this script to run fast (its better I think to run it with some timeouts because of the server glitches and bottlenecks). What is more important is to make it automatic so one can start it over the night, over the weekends. Number of the URLs would be around 10, and list of keywords from few tens, to a few hundred. If I can provide some additional clarification and info I'm available. Of course I would be willing to pay someone to help me accomplish this task. Cheers Dean Edited by dolke022, 19 August 2014 - 07:54 AM. Hi there I am having trouble with the code below The difficulty is with this bit I think ('input type="submit"','value="Submit"') Many thanks Doug <?php echo tep_draw_form('advanced_search', tep_href_link(FILENAME_ADVANCED_SEARCH_RESULT, '', 'NONSSL', false), 'get') . tep_draw_hidden_field('search_in_description','1') . tep_draw_input_field('keywords', TEXT_ENTER_KEYWORDS , 'size="10" maxlength="30" onFocus="emptyMe()" style="width: ' . (BOX_WIDTH-25) . 'px"'); ?> <?php echo tep_hide_session_id() . ('input type="submit"','value="Submit"') . '</form>';?> hii..
i want a travel search engine script in php website. i am searching for 2 to 3 days on it.
but i dont know how to start. i searched on google. find sme APIs for it. but where to implement those APIs. what code i need to write for it.
it would be grateful if anyone give some suggestions on this.
thanks and regards.
So let's assume i'm making a script for searching cars by different criteria. Name of the car, color, and mileage. I used to do this by using LIKE and just adding AND for as many times as needed. But i've read that that is obsolete and is giving servers a hard time, so i went ahead and started making a new script that will use fulltext search. I've hit a dead end. Code: [Select] function search($table,$what,$string,$limit,$start,$country) { global $totrows; global $pages; $string = explode("*",$string); $what = explode("*",$what); $cname = trim($string[0]); $t = 0; $parameters = ""; while (isset($what[$t])){ if ($t>0) { $paramm .= ", "; } $paramm .= trim($what[$t]); if ($t>0) { $parama .= " "; } $parama .= trim($string[$t]); $t++; } $parameters .= " AND locationc = '".$country."'"; $sql = "SELECT *, MATCH(".$paramm.") AGAINST('".$parama."') AS score FROM main WHERE MATCH(".$paramm.") AGAINST('".$parama."') ORDER BY score DESC"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { var_dump($row); } } How does this work: The user selects and enters his parameters> The script then joins them all into a single variable which is then sent to the function(the reason i do this i because the user might input only the name, so that way i can add more criteria and not need to change the script)> The script explodes those into arrays and then it processes them into a form for use with sql> I run the sql query and then return the results. What's the problem? There's two of them actually> The first one is that mysql returns an error "Can't find FULLTEXT index matching the column list" even though i did setup fulltext indexes. (phpmyadmin c/p) Code: [Select] name FULLTEXT No No name 0 YES color FULLTEXT No No color 0 YES mileage FULLTEXT No No mileage 0 YES The second problem is that the script is not selective and will not work as intended. For example, a car's name is 300, the users input's 300, and the script will return those rows that had mileage 300 or 300000 or whatever. How do i fix this, and is FULLTEXT the right way to go with multi criteria search? Hello folks, I've got a problem with a search script. It's searching a db containing various properties (as in buildings) and it's not quite returning the correct results. The search form asks that you select a house type (4 options, all of which are tick boxes) and then the last part of the form is select how many bedrooms you'd like (which is a drop-down list featuring numbers 2-5) What should happen is someone selects one or more of the tick boxes and then the number of bedrooms and it returns all the house types that were ticked but only those with the number of bedrooms that were specified in the original search. Currently the results are correct in that they're showing the correct house types, but the number of bedrooms isn't right. e.g. if you chose 2 bedrooms in the search it shows those, as well as 3, 4 and 5 bedrooms in the results. Can't figure it out but it will be something to do with && and OR in my search script. Can anyone suggest a tweak to this that might work? (I'm using the $_GET function because the search form is in a Flash movie) $Result = mysql_query("select * from property_names where TownHouse = '$_GET[TownHouse]' OR Apartment = '$_GET[Apartment]' OR Detached = '$_GET[Detached]' OR SemiDetached = '$_GET[SemiDetached]' && visible= 'Yes' && bedrooms = '$_GET[Bedrooms]' && bedrooms = '$_GET[Bedrooms]'") Hi guys and girls, I am having trouble finding out wether the query made no matches rather than just displaying the matches. So what I would want is for the search term to look at the database, and if there's not matches then say, "No match for your search term" Code: [Select] function search_applications() { global $dbc; echo '<form method="post" action="" id="search">'. "\n"; echo '<label for="search_applications">Search for an application</label>'. "\n"; echo '<input type="text" name="search_applications" />'. "\n"; echo '<input type="submit" name="submit" />'. "\n"; echo '</form>'. "\n"; if(isset($_POST['submit'])){ $search_applications = $_POST['search_applications']; if ($search_applications == "") { echo "<p>You forgot to enter a search term"; } //if (preg_match("/\b$search_applications\b/i")){ if(preg_match("/^[ a-zA-Z]+/", $search_applications)){ //for testing the variables //echo $search_applications; $sql="SELECT title, category, content FROM distributors_content WHERE title LIKE '%" . $search_applications . "%' OR category LIKE '%" . $search_applications ."%' OR content LIKE '%" . $search_applications ."%'"; $result=mysqli_query($dbc, $sql); //-create while loop and loop through result set while($row=mysqli_fetch_array($result)){ $title =$row['title']; $category=$row['category']; $content=$row['content']; //-display the result of the array echo "<ul>\n"; echo '<li> <a href="index.php?article='.$row['title'].'&&page=application" title=""> '.$title . ' ' . $category . '</a></li>'."\n"; echo "</ul>"; } }else{ echo "<p>Enter another search term</p>"; } } } Any pointers would be good Thank you Im having problems with this code in my search button script. I get the following error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource Here's the code I use on my search form. Code: [Select] <form method="post" action="srch_all.php"><input type=text name='search' size=15 maxlength=255><br><input type=submit></form> and here's the code I'm using to perform the search query: Code: [Select] if ($search) // perform search only if a string was entered. { mysql_connect($host, $user, $pass) or die ("Problem connecting to Database"); $srch="%".mysql_real_escape_string($search)."%"; $query = "select * from database WHERE column1 LIKE '$srch' or column2 LIKE '$srch' or column3 LIKE '$srch' or column4 LIKE '$srch' ORDER BY column1, column2 DESC, column3 ASC"; $result = mysql_db_query("database_name", $query); if(mysql_num_rows($result)==0) { print "<h2>Your search returned 0 Results</h2>"; } else if ($result) { <restult data stuff here>.. Cheers I have a simple (1 table, 14 fields) database. I'm using 9 separate search boxes from my search page : http://www.cinemaposter.com/database.html There are currently 162 entries. Hitting "submit" throws them all out, same with valid input into any box, with the exception of "country" - example : entering "F" gives 20results; "PL" gives 34 results. Here's my code (to simplify, I only went down to the 4th box ('country' - the last and only one giving correct results). I'm one sorry newbie.... please help ! Here's the code : ------------------ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd"> <html> <head> <title>Search Results</title> <meta name="generator" content="BBEdit 6.5"> <style type="text/css"> td { color: #000000; font-family: arial; font-size: 10px; } </style> </head> <body> <?php $link = mysql_connect("xxxx", "xxxx", "xxxx") or die("Could not connect"); ///print "Connected successfully<BR>"; mysql_select_db("xxxx") or die("Could not select database"); { $Author = $_POST['Author']; $sql = "SELECT * FROM posters WHERE Author LIKE '%$Author%'"; } { $Title = $_POST['Title']; $sql = "SELECT * FROM posters WHERE Title LIKE '%$Title%'"; } { $Originaltitle =$_POST['Originalitle']; $sql="SELECT * FROM posters WHERE Originaltitle LIKE '%$Originaltitle%'"; } { $Country =$_POST['Country']; $sql="SELECT * FROM posters WHERE Country LIKE '%$Country%'"; } $result = mysql_query ($sql) or die("Query failed : " . mysql_error()); $numrs = mysql_num_rows($result); if ($numrs > 0){ if ($numrs==1){ print ("<p><font face=\"Arial\"><b>There is $numrs record in our database.</B> <BR><BR>"); }elseif($numrs>1){ print ("<p><font face=\"Arial\"><b>There are $numrs records in our database. </B><BR><BR>");//Apparently, he wan't to be able to search again...</b><form method \"POST\" action=\"$PHP_SELF\">Search Again:"); } echo("<a href='javascript:history.go(-1)'>Go Back</a></p>"); print("<P align=center>Click on the column heading links to sort the results.<br><br />"); print ("<TABLE CELLPADDING=\"1\" CELLSPACING=\"2\" BORDER=\"0\">\n"); PRINT ("<TR BGCOLOR=\"#FFFF77\"> <TD COLSPAN=2><P align=center>Author</td> <TD><P align=center>Title</TD> <TD><P align=center>Original Title</TD> <TD><P align=center>Country</TD> <TD><P align=center>Director</TD> <TD><P align=center>Cast</TD> <TD><P align=center>Year</TD> <TD><P align=center>Original Year</TD> <TD><P align=center>Photo</TD> <TD><P align=center>Producer</TD> <TD><P align=center>Circulation</TD> <TD><P align=center>Size</TD> <TD><P align=center>Print type</TD> <TD><P align=center>Remarks</TD></TR>"); $z=1; while ($line = mysql_fetch_array($result)) { $num=$z++; //Note here that I'm assigning the found objects new names (indicated by lowercase) to that php wont get confused..... $auth=$line['Author']; $title=$line['Title']; $originaltitle=$line['Originaltitle']; $country=$line['Country']; $director=$line['Director']; $cast=$line['Cast']; $year=$line['Year']; $originalyear=$line['Originalyear']; $producer=$line['Producer']; $circ=$line['Circulation']; $size=$line['Size']; $print=$line['Print']; $remarks=$line['Remarks']; $pict=$line['Picture']; //Set the formatting $bgcolor = ($i++ & 1) ? '#d3d3d3' : '#c0c0c0'; PRINT("<TR BGCOLOR=$bgcolor> <TD>$num.</TD> <TD>$auth</td> <TD>$title</TD> <TD>$originaltitle</TD> <TD><P align=center>$country</TD> <TD>$director</TD> <TD>$cast</TD> <TD><P align=center>$year</TD> <TD><P align=center>$originalyear</TD><TD>"); // This is the test to find do we have a picture if ($pict) { // If there is a picture, display it: print ("<P align=center><a href='zdjecie.php?zdj= $pict&autor=$auth&opis=$title&orig=$originaltitle&rok=$year' target='_blank'> <img src=$pict height=\"150\"></a>"); } else { // We don't have a picture, so we print some text instead: print ("<P align=center>no picture available"); } print ("</TD><TD>$producer</TD> <TD><P align=center>$circ</TD> <TD>$size</TD> <TD>$print</TD> <TD>$remarks</TD></TR>"); } PRINT("</TABLE><BR><font face=\"Arial\"><a href=\"javascript:history.go(-1);\">Search Again</a></font>"); }else { print ("<font face=\"Arial\">Sorry, there were no results for your search. <a href=\"javascript:history.go(-1);\">Please try again</a></font>"); } //mysql_close($link); ?> </body> </html> Ok, so I have a bit of code but it's not working as it should, would one of you guys have a look at it and let me know where I'm going wrong? Basically I need to be able to input several words or terms into the text area, each on a separate line and have the results displayed something like: hello: 23,000.000 hello world: 19,000,000 world: 278,000,000 I also see that the script is not searching the words / terms inside quotes (EG. "hello world") TIA Code: [Select] <html> <body> <?php function my_fetch($url,$user_agent='Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)') { $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/'); $result = curl_exec ($ch); curl_close ($ch); return $result; } $s = $_GET['s']; if (isset($s)) { echo "<p><i>Search for $s</i></p>"; $s = urlencode($s); $data = my_fetch("http://www.google.com/search?hl=en&q=" . $s . "&btnG=Google+Search"); $data = strip_tags($data); $find = 'Results 1 - 10 of about '; $find2 = ' for'; $data = strstr($data, $find); $pos = strpos($data, $find2); $search_number=substr($data,strlen($find), $pos-strlen($find)); echo "Total Results: $search_number"; } else { ?> <form name="form1" id="form1" method="get" action=""> <div align="left"> <p> <textarea name="s" type="text" id="s" rows="8" style="width:60%" /></textarea><br /> <input type="submit" name="Submit" value="Results" /></p> Put "" around the string: <input type="checkbox" checked name="apos" value="true" /><br /> </div> </form> <p> <?php } ?> </p> </body> </html> |