PHP - Search Menu Problem
Good morning,
Its about this website www.deltaboatcenter.nl Boats page! I wanna search tough the boats we are selling with a seach menu, the menu is there (see website) but is got 2 scrips (below) the first one i use now the boats preview nicely on the website and work good but cant search with the boat menu for boat brands. the second one does search trough boat brands but doenst come up with boats at all.. Code: [Select] <?php include('dbclass/db.php'); include('define.php'); //////////include('pagination.class.php'); include('include/ps_pagination.php'); include_once('classes/easyphpthumbnail.class.php'); $thumb = new easyphpthumbnail; $thumb -> Thumbheight = 140; $thumb -> Thumbwidth = 200; $thumb -> Thumblocation = 'thumb/'; $thumb -> Thumbprefix = 'thumb_'; $thumb -> Thumbsaveas = 'png'; if($lang == 'eng') { $header = "header_eng.php"; $footer = "footer_eng.php"; $where = 'language_id=1'; $language =1; } elseif($lang == 'dutch') { $header = "header_dutch.php"; $footer = "footer_dutch.php"; $where = 'language_id=2'; $language =2; } elseif($lang == 'german') { $header = "header_german.php"; $footer = "footer_german.php"; $where = 'language_id=3'; $language =3; } else { $header = "header_eng.php"; $footer = "footer_eng.php"; $where = 'language_id=1'; $language =1; } //select query $obj = new Database; $obj ->select('english_boats','',$where); $query= "select * from english_boats where language_id=$language"; $pager = new PS_Pagination($obj->getConnection(),$query,5,3); $rs = $pager->paginate(); /////////var_dump($rs); ///////exit; $sel= "select * from english_boats"; /// $q=mysql_query($sel) or die mysql_error(); //generate thumbnail // include('boat_function.php'); ?> <!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> <script type='text/javascript' src='jspop/jquery.js'></script> <script type='text/javascript' src='jspop/jquery.simplemodal.js'></script> <script type='text/javascript' src='jspop/osx.js'></script> <script src="prototype.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Delta Boat company boat listing</title> <link href="boatstyle/boatstyle.css" rel="stylesheet" type="text/css" /> </head> <body class="background"> <script> function dosubmit( ) { new Ajax.Updater( 'result', 'search_boat.php', { method: 'post', parameters: $('myform').serialize() } ); $('myform').reset(); } //get_call function get_call( ) { if(document.calform.name.value=="") { //inlineMsg('name','please enter the name',20); alert('Please enter the name'); document.calform.name.focus(); return false; } var phone = /-\d{7}/ ; if(!phone.test(document.calform.tel_number.value)) { alert('Please enter the telephone number'); document.calform.tel_number.focus(); return false; } var aemail= /^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$/; if(!aemail.test(document.calform.email.value)) { alert('Please enter the valid email address'); document.calform.email.focus(); return false; } new Ajax.Updater( 'get_result', 'make_home_appointment.php', { method: 'post', parameters: $('calform').serialize() } ); $('calform').reset(); } </script> <div class="container"> <?php include($header); ?> <div class="clear"></div> <div class="line"></div> <div class="searchPanel"> <div class="searchTop"></div> <div class="clear"></div> <div class="searchMid"> <div class="searchTitle">Search</div> <div class="searchForm"> <!--javascript:get(document.getElementById('myform'));--> <form id="myform"> <input type="hidden" name="language" value="<?php echo $language;?>" /> <table class ="textboxAlign" width="100%" border="0"> <tr> <td width="38%" class="searchItem">Brand:</td> <td width="62%" class="searchItem"><div class="textboxAlign"> <select name="brand" id="brand" style="width:140px"> <option value="any">any</option> <?php while($r_b =mysql_fetch_array($q)){ ?> <option value="<?php echo $r_b['boat_brand'];?>"><?php echo $r_b['boat_brand'];?></option> <?php }?> <!-- <option value="brand B">Company B</option> <option value="brand C">Company C</option> <option value="brand D">Company D</option>--> </select> </div></td> </tr> <tr> <td nowrap="nowrap" class="searchItem">Year From:</td> <td class="searchItem"><div class="textboxAlign"> <input type="text" name="year_from" id="year_from" value="any" size="5" onfocus="if(this.value == this.defaultValue) this.value = ''"/> To: <input type="text" name="year_to" id="year_to" value="any" size="5" onfocus="if(this.value == this.defaultValue) this.value = ''"/> </div> </td> </tr> <tr> <td class="searchItem">Price From:</td> <td class="searchItem"><div class="textboxAlign"> <input type="text" name="price_from" id="price_from" value="any" size="5" onfocus="if(this.value == this.defaultValue) this.value = ''"/> To: <input type="text" name="price_to" id="price_to" value="any" size="5" onfocus="if(this.value == this.defaultValue) this.value = ''"/> </div></td></tr> <tr> <td class="searchItem" valign="top">Features:</td> <td nowrap="nowrap" class="searchItem"><input type="checkbox" name="heating" id="heating" value="588" /> Heating System</td> </tr> <tr> <td> </td> <td class="searchItem"> <input type="checkbox" name="generator" id="generator" value="661" /> Generator</td> </tr> <tr> <td> </td> <td class="searchItem" align="left"> <input type="checkbox" name="bow" id="bow_thruster" value="297" /> Bow Thruster</td> </tr> <tr> <td> </td> <td class="searchItem"> <input type="checkbox" name="stern" id="stern_thruster" value="964" /> Stern Thruster</td> </tr> <tr> <td colspan="2" align="center"> <input type="button" onclick="dosubmit()" value="Search"> <!-- <input type="button" name="button" class="button" value="Search" onclick="javascript:get(this.parentNode);" />--> </td> </tr> </table> </form> </div> </div> <div class="searchBase"></div> <div class="clear"></div> </div> <div id="result"> <div class="thumbnailsDisplayArea"> <?php if(!isset($_GET['page']) || ($_GET['page']==1)) { $i=1; } else { $i=(($_GET['page']-1)*10)+1 ; } if(mysql_num_rows($rs)>0) { while($row_fetch=mysql_fetch_assoc($rs)) {?> <?PHP $i++; ?> <div class="listPanel"> <div class="listTop"></div> <div class="listMid"> <a href="boat_detail.php?id=<?php echo $row_fetch ['boat_id'];?> & common_id=<?php echo $row_fetch['common_id']; ?>"><div class="itemName" align="left"><?php echo $row_fetch['boat_title'];?> </div></a> <div class="itemPrice"><?php echo $row_fetch['price_currency'];?> <?php echo $row_fetch['boat_price'];?></div> <div class="clear"></div> <div class="itemDescription" align="left"> <a href="boat_detail.php?id=<?php echo $row_fetch['boat_id'];?>&common_id=<?php echo $row_fetch['common_id']; ?>"><?php echo $row_fetch['boat_summary'];?></a> <div class="moreLink"><!--<a href="boat_detail.php?id=<?php //echo $value['boat_id'];?> & common_id=<?php //echo $com_id?>">more...</a>--></div> <div class="clear"></div> </div> <div class="ItemThumbnail"> <a href="boat_detail.php?id=<?php echo $row_fetch ['boat_id'];?>&common_id=<?php echo $row_fetch['common_id'];?>"> <?php ///////exit; $where=sprintf("common_id=%d",$row_fetch['common_id']); $obj ->select('boat_images','',$where); $array = $obj ->get(''); if(count($array)>0){ $imagename=$array[0]["boat_image"]; $thumb_name="thumb/thumb_$imagename"; $thumb_name=str_replace("jpg","png",$thumb_name); if(!file_exists($thumb_name)) { $thumb -> Createthumb("admin/uploads/$imagename","file"); } ?><?php } ?> <img src="<?php echo $thumb_name; ?>" border=0 /> </a><br /> </div> </div> <div class="listBase"></div> </div> <div class="clear"></div> <?php }}else { echo 'NO image found';}?> <div class="paging2"> <?php if(mysql_num_rows($rs)>0){ echo $pager->renderFullNav(); }?> <div class="clear"></div> </div></div> <div class="verticalSpacer"></div> <div class="clear"></div> <div class="line"></div> <div class="footer"> <?php include($footer);?></div> <?php include('language.php');?> <div class="clear"></div> </div> </div> </body> </html> Code: [Select] <?php include('dbclass/db.php'); include('define.php'); if($lang == 'eng') { $header = "header_eng.php"; $footer = "footer_eng.php"; $where = 'language_id=1'; $language =1; } elseif($lang == 'dutch') { $header = "header_dutch.php"; $footer = "footer_dutch.php"; $where = 'language_id=2'; $language =2; } elseif($lang == 'german') { $header = "header_german.php"; $footer = "footer_german.php"; $where = 'language_id=3'; $language =3; } else { $header = "header_eng.php"; $footer = "footer_eng.php"; $where = 'language_id=1'; $language =1; } //select query $obj = new Database; $obj ->select('english_boats','',$where); $array = $obj ->get(''); //get brands $s = "select distinct boat_brand from english_boats"; $q = mysql_query($s) or die(mysql_error()); //generate thumbnail ?> <!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> <script type="text/javascript" language="javascript"> var http_request = false; function makeRequest(url, parameters) { http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { // set type accordingly to anticipated content type //http_request.overrideMimeType('text/xml'); http_request.overrideMimeType('text/html'); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Cannot create XMLHTTP instance'); return false; } http_request.onreadystatechange = alertContents; http_request.open('GET', url + parameters, true); http_request.send(null); } function alertContents() { if (http_request.readyState == 4) { if (http_request.status == 200) { //alert(http_request.responseText); result = http_request.responseText; document.getElementById('myspan').innerHTML = result; } else { alert('There was a problem with the request.'); } } } function get(obj) { var getstr = "?"; for (i=0; i<obj.childNodes.length; i++) { if (obj.childNodes[i].tagName == "INPUT") { if (obj.childNodes[i].type == "text") { getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&"; } if (obj.childNodes[i].type == "hidden") { getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&"; } if (obj.childNodes[i].type == "checkbox") { if (obj.childNodes[i].checked) { getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&"; } else { getstr += obj.childNodes[i].name + "=&"; } } if (obj.childNodes[i].type == "radio") { if (obj.childNodes[i].checked) { getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&"; } } } if (obj.childNodes[i].tagName == "SELECT") { var sel = obj.childNodes[i]; getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&"; } } document.getElementById('myspan').innerHTML = '<img src="images/wait30trans.gif" alt="loading" />' + 'Loading'; //setTimeout('alert(\'Surprise!\')', 5000); makeRequest('search_boat.php', getstr); } </script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Delta Boat company about us</title> <link href="boatstyle/boatstyle.css" rel="stylesheet" type="text/css" /> </head> <body class="background"> <div class="container"> <?php include($header); ?> <div class="clear"></div> <div class="line"></div> <div class="searchPanel"> <div class="searchTop"></div> <div class="clear"></div> <div class="searchMid"> <div class="searchTitle">Search</div> <div class="searchForm"> <!--javascript:get(document.getElementById('myform'));--> <form action="javascript:get(document.getElementById('myform'));" name="myform" id="myform"> <!--<form action="" name="form">--> <table class ="textboxAlign" width="100%" border="0"> <tr> <td width="38%" class="searchItem">Brand:</td> <td width="62%" class="searchItem"><div class="textboxAlign"> <select name="brand" id="brand" style="width:140px"> <option value="any">any</option> <?php while($r_b =mysql_fetch_array($q)){ ?> <option value="<?php echo $r_b['boat_brand'];?>"><?php echo $r_b['boat_brand'];?></option> <?php }?> <!-- <option value="brand B">Company B</option> <option value="brand C">Company C</option> <option value="brand D">Company D</option>--> </select> </div></td> </tr> <tr> <td nowrap="nowrap" class="searchItem">Year From:</td> <td class="searchItem"><div class="textboxAlign"> <input type="text" name="year_from" id="year_from" value="any" size="5" onfocus="if(this.value == this.defaultValue) this.value = ''" /> To: <input type="text" name="year_to" id="year_to" value="any" size="5" onfocus="if(this.value == this.defaultValue) this.value = ''" /> </div> </td> </tr> <tr> <td class="searchItem">Price From:</td> <td class="searchItem"><div class="textboxAlign"> <input type="text" name="price_from" id="price_from" value="any" size="5" onfocus="if(this.value == this.defaultValue) this.value = ''" /> To: <input type="text" name="price_to" id="price_to" value="any" size="5" onfocus="if(this.value == this.defaultValue) this.value = ''" /> </div></td></tr> <tr> <td class="searchItem" valign="top">Features:</td> <td nowrap="nowrap" class="searchItem"><input type="checkbox" name="heating" id="heating" value="588" /> Heating Sysytem</td> </tr> <tr> <td> </td> <td class="searchItem"> <input type="checkbox" name="generator" id="generator" value="661" /> Generator</td> </tr> <tr> <td> </td> <td class="searchItem" align="left"> <input type="checkbox" name="bow" id="bow_thruster" value="297" /> Bow Thruster</td> </tr> <tr> <td> </td> <td class="searchItem"> <input type="checkbox" name="stern" id="stern_thruster" value="964" /> Stern Thruster</td> </tr> <tr> <td colspan="2" align="center"> <input type="button" name="button" class="button" value="Submit" onclick="javascript:get(this.parentNode);" /> </td> </tr> </table> </form> </div> </div> <div class="searchBase"></div> <div class="clear"></div> </div> <div id="myspan"> <div class="thumbnailsDisplayArea"> <?php if(count($array)) { while(list($k,$value) = each($array)) { $com_id = $value['common_id']; $im_where = 'common_id='.$com_id; $obj ->select('boat_images','',$im_where); $im_array = $obj ->get(''); $filename = $im_array[0]['boat_image']; ?> <div class="listPanel"> <div class="listTop"></div> <div class="listMid"> <a href="boat_detail.php?id=<?php echo $value['boat_id'];?> & common_id=<?php echo $com_id?>"><div class="itemName" align="left"><?php echo $value['boat_title'];?> </div></a> <div class="itemPrice"><?php echo $value['price_currency'];?> <?php echo $value['boat_price'];?></div> <div class="clear"></div> <div class="itemDescription" align="left"> <a href="boat_detail.php?id=<?php echo $value['boat_id'];?>&common_id=<?php echo $com_id?>"><?php echo $value['boat_summary'];?></a> <div class="moreLink"><!--<a href="boat_detail.php?id=<?php //echo $value['boat_id'];?> & common_id=<?php //echo $com_id?>">more...</a>--></div> <div class="clear"></div> </div> <div class="ItemThumbnail"><a href="boat_detail.php?id=<?php echo $value['boat_id'];?>&common_id=<?php echo $com_id?>"><?php //createThumbnail($filename);?><img src="admin/uploads/<?php echo $im_array[0]['boat_image'];?>" width="200px" height="140px" border="0" /></a></div> </div> <div class="listBase"></div> </div> <?php }}?> <div class="clear"></div> </div> </div> <div class="verticalSpacer"></div> <div class="clear"></div> <div class="line"></div> <div class="footer"> <?php include($footer);?></div> <?php include('language.php');?> <div class="clear"></div> </div> </body> </html> The strange thing is both scripts work but not good. the first one wont seach trou the boat list. and the second one does but doesent show the boats in the first place.. Does some one has any idea what i'm doing wrong? Kind regarts Similar TutorialsHello I am having a trouble with creating page that will search records from database using dropdown menu, when I select a category, for example By: Gender and after clicking the Submit button, there is no records displays but when I select By: ALL, the records displays. What's wrong with my code? I'm sorry I'm fairly new to PHP. Here is my code: Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Search</title> </head> <body> <form action="" method="POST" name="records"> <label>SEARCH: </label> <select name="select"> <option value="all" selected="selected">ALL</option> <option value="year">By Year</option> <option value="gender">By Gender</option> <option value="course">By Course</option> </select> <input name="submit" value="GO" type="submit" /> <br /> </form> </body> </html> <?php include('collegeinfo_connect.php'); mysql_connect("$server", "$user", "$pass")or die("cannot connect"); mysql_select_db("$db")or die("cannot select DB"); if (isset($_POST['submit'])) { $selection = $_POST['select']; if($selection == "all") $query = "SELECT * FROM collegeinfo_tbl"; else if($selection == "year") $query = "SELECT * FROM collegeinfo_tbl WHERE Year='year'"; else if($selection == "gender") $query = "SELECT * FROM collegeinfo_tbl WHERE Gender='gender'"; else if($selection == "course") $query = "SELECT * FROM collegeinfo_tbl WHERE Course='course'"; } if (isset($query)) { $result = mysql_query($query) or die(mysql_error()); echo "<br /> <br />"; echo "<table border='1' cellpadding='10'>"; echo "<tr> <th>ID Number:</th> <th>First Name:</th> <th>Last Name:</th> <th>Gender:</th> <th>Year:</th> <th>Course:</th> </tr>"; while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo '<td>' . $row['ID'] . '</td>'; echo '<td>' . $row['FirstName'] . '</td>'; echo '<td>' . $row['LastName'] . '</td>'; echo '<td>' . $row['Gender'] . '</td>'; echo '<td>' . $row['Year'] . '</td>'; echo '<td>' . $row['Course'] . '</td>'; echo "</tr>"; } echo "</table>"; } ?> This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=353763.0 Hi, Can I know how to resolve this problem? Notice: Undefined variable: x in C:\wamp\www\i-document\search.php on line 39 Notice: Undefined variable: construct in C:\wamp\www\i-document\search.php on line 41 1 results found! Thankz. <html> <body> <form id="form1" method="GET" action="search.php"> <table width="446" height="135" border="1" align="center"> <tr> <td height="31" colspan="2" align="center" valign="middle" bgcolor="#990000"><span class="style1 style2">Search :</span></td> </tr> <tr> <td width="374" height="96" align="center" valign="middle" bgcolor="#990000"><span class="style1 style2"> <label> <div align="left">Keyword : <input name="search" type="text" id="search" size="40" /> </div> </label> </span> <td width="56" align="center" valign="middle" bgcolor="#990000"> <div align="left"> <input type = "submit" name="submit" value="search" /> </div></td> </tr> </table> </form> </body> </html> [b][u]search.php[/u][/b] <html> <title>Search</title> </head> <body><br /><br /> <div class="MySearch"></div><br /> <?php //Get data $button = $_GET['submit']; $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 <b>$search</b><hr size='1'>"; //connect to database mysql_connect("localhost","root",""); mysql_select_db("idoc"); //explode search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each); { //Construct Query $x++; if ($x==1) $construct .= "file_name LIKE '%$search_each%'"; else $construct .= " OR file_name LIKE '%$search_each%'"; } //echo out construct $construct = "SELECT * FROM document WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "No results found"; else { echo "$foundnum results found!<p>"; while ($runrows = mysql_fetch_assoc($run)) { //Get data $ref = $runrows['file_ref']; $filename = $runrows['file_name']; $owner = $runrows['owner']; $url = $runrows['url']; echo " <table> <tr> <td> $ref </td> <td> $filename </td> <td> $owner </td> <td><a href='$url'>$url</a></td> </tr> </table> "; } } } } ?> Hi ; I have problem with search script ; This is code ; $search_form = "<form method='get' action='' ><span class='aktif'>Arama</span><input class='aktif' type='text' name='search' ><input class='aktif' type='submit'></form>"; echo $search_form ; $search = isset($_GET['search']) ? trim($_GET['search']): ''; $a1=(str_replace(' ', '',$search) ); $S1 = ' '; $S2 = ' '; $S3 = ' '; if($search != ''){ // Terimlerin Arama Kısmı $S1 = sprintf("WHERE Tetik_Ref like '%%%s%%' OR ",mysql_real_escape_string($search)); $S2 = sprintf("Marka_Model like '%%%s%%' OR",mysql_real_escape_string($search)); $S3 = sprintf("Orj_P_N like '%%%s%%'",mysql_real_escape_string($search)); } //Verilerin yazdırılma işlemi $main_query = "SELECT * FROM ats_motor $S1 $S2 $S3 "; $count_query = "SELECT COUNT(*) FROM ats_motor $S1 $S2 $S3 ";Orj_P_N column inside Original Part Numbers. Its same of "111 11 111" or "15K 1245 45" etc. When i search exact records work fine. But I search 11111111 nothing found. I search that and find str_replace function. But i cant use that. Cant import. I try change line 8 and 14. it give me error. Can anybody help me ? Thanks. Edited by Seorniyc, 15 May 2014 - 09:55 AM. Hey guys im just starting to use Prepared Statements in php and i am trying to build a search but i have come across a problem. Hope someone can help or point me to more information on how to resolves this. Ok here is the code below:: public function search($string) { if(strlen($string) > 40) { return "Woow too many words, please shorten your search."; } if(empty($string)) { return "I'm a search, you type things in and I find. Please enter something and try again!"; } if(strlen($string) <= 3) { return "Come on dude, you expect me to find summin with that? Type some more tags in!"; } $x=0; // Teh string could be multiple searches so explode:: $string = explode(" ", $string); foreach($string as $search) { $x++; if($x == 1) { @$sql .= "(blog_tags LIKE '%$search%')"; } else { @$sql .= " OR (blog_tags LIKE '%$search%')"; } } $sql = "SELECT blog_tags FROM subarc_blog WHERE $sql LIMIT 40"; // TODO:: Count how many search results found:: $stmt = $this->conn->prepare($sql); $stmt->execute(); $stmt->bind_result($search); Ok by using the bind_result() i need to know how many result are being returned to add them to a variable is this correct ? if so how can i tell how many results have been returned ? hope this makes sense I have a number of records of the html sections of a series of Google Earth placemarks that I managed to extract from the raw kml file. The purpose of the exersize was to then use the simplehtmldom.php api to extract the DATA from the raw html code. Some of the process is going well... and some is NOT. I have found that if I modify the raw html code by entering ID attributes into the html code the simplehtmldom api has an easy time identifying the desired data, and the data can be far 'cleaner' by entering an id attribute as 'close' to the data as possible. But doing a php text search and replace often requires finding a 'unique' identifyable portion of the html code and THEN placing the 'id' attribute in a nearby html tag because the desired data is nested inside a non-unique tag. As in I can identify a SPECIFIC <td> tag section where the data i desire is located but the data is nested inside a <font> tag inside the <td> cluster. Hence my problem... If I do a search in the following code... Code: [Select] <td><b><font size="+2" color="#FF0000">Neighborhood:</font> <font size="+2" color="#0000FF">City of Sidney</font></b></td> I can locate the 'Neighborhood:' string because it is unique in the whole html code. Then by some charcter counting I am desiring to put my 'id' attribute in the NEXT font tag because it surrounds the desired data the 'City of Sidney'... as in... Code: [Select] <td><b><font size="+2" color="#FF0000">Neighborhood:</font> <font id="neighborhood" size="+2" color="#0000FF">City of Sidney</font></b></td> With this modification the desired data is easily found and cleanly produced. But the html code while all operating correctly in a web page is not all identicle from a 'whitespace' point of view AND thus my problem. If I search the following code... Code: [Select] <td> <b><font size="+2" color="#FF0000">Neighboorhood:</font> <font size="+2" color="#0000FF">Greenacre</font></b> </td> While being identical as far as html is concerned if I search this code for the 'Neighboorhood:' identifier I find it... but then attempting to place the id tag into the NEXT font tag is being problematic. What i seem to need is a function that once the 'Neighboorhood:' string position is identied and noted in the whole of the html code, to FIND and modify the NEXT occurance of a font tag no matter what whitespace (or special charachters) may be occuring. Any suggestions?? eatc7402 Looking for some technical assistance on a property search query im having some problems with on WP. Using the Agentpress theme I have put together a client site that is fully functional, however the client has asked that the search is altered is altered slightly and i'm having trouble working out how to do it. I'm not a database / PHP person - I have managed so far, but this is beyond my understanding. I have 2 separate search query issues. The first is that my client wants the bedrooms to be searchable with the following options: 1 or more 2 or more 3 or more 4 or more The second is that they want the availability of the property to only give 2 options: Availabile properties only Include Let Agreed Here is the site: test.taylorslettings.co.uk The property data and field names I have are being automatically created by their system and provides the information in the dropdowns as you see it in the search box on the site. The theme (Agentpress) dictates the search and how it works at present. I have no idea how to alter the search so it shows presents the results to meet the clients needs. We are at the very end stages of going live, so any urgent help would be gratefully appreciated. Thanks very much. Hi all. This is the code I've been trying to execute. <?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>No search parameter</p>"; exit; } //connect to your database ** EDIT REQUIRED HERE ** mysql_connect("localhost","*","*"); //(host, username, password) //specify database ** EDIT REQUIRED HERE ** mysql_select_db("my_db") or die("Can't select database//Does not exist."); //select which database we're using // Build SQL Query $query = "select * from people \"%$trimmed%\" order by FirstName"; // 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["FirstName"]; 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>"; ?> As you can see, it's pretty simple and it's got very nice explanations of what everything does. But when I try it, I get this. Quote Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\Program Files\xampp\xampp\htdocs\search.php on line 36 Results Sorry, your search: "Ella" returned zero results Click here to try the search on Google Couldn't execute query I'm pretty much stuck. Any ideas what that error means? And yes, there is a entry with the name of Ella in the people table of the database. Help? I have a problem with database search for a member. I am pretty sure my sql is correct. It must be my if statements. Upon submitting the search for a member, even if there is not a match, the link appears for the member that was entered into the search. I only want the link to show up if there is a match. Thank you in advance. Code: [Select] <?php error_reporting(E_ALL); require_once("./include/membersite_config.php"); //session_start();//FOR GETTING USER ONLINE SCRIPT header("Cache-Control: nocache"); header("Expires: 0"); if(!$fgmembersite->CheckLogin()) { $fgmembersite->RedirectToURL("login.php"); exit; } $currentUser=$_SESSION['name_of_user']; // set current user name logged in to $currentUser to grab his profil DB data later. if(!$fgmembersite->CheckLogin()) { $fgmembersite->RedirectToURL("login.php"); exit; } //define a maxim size for the uploaded images in Kb define ("MAX_SIZE","100"); //This function reads the extension of the file. It is used to determine if the file is an image by checking the extension. function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } //This variable is used as a flag. The value is initialized with 0 (meaning no error found) //and it will be changed to 1 if an errro occures. //If the error occures the file will not be uploaded. $errors=0; include 'memberHeader.php'; if (isset($_POST['submit'])) { $memberSearch=$_POST['memberSearch']; mysql_connect(" ", " ", " ") or die(mysql_error()); // info left out mysql_select_db(" ") or die(mysql_error()) ; $sql = "SELECT username FROM users WHERE username='$memberSearch'"; $result = mysql_query($sql); echo $result; if (!$result) { echo "no matching member found " . mysql_error(); exit; } if($result) { echo "Your search result link: <a href='viewProfile.php?userPage=".$memberSearch."'>click here for result</a>"; } ////////////////////////////////MEMBER SEARCH FORM////////////// } ?> <!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>Untitled Document</title> </head> <body> <p> </p><p> </p><p><? echo "<p> </p><p></p><form id='form1' name='form' method='post' action=''> Enter a member's name here to search <input type='text' name='memberSearch' id='memberSearch' /> <input type='submit' name='submit' id='submit'/> </form>"; ?> </p> </body> </html> Hello , i need some help on this line. Line: $compose_a = mysql_query("SELECT * FROM users WHERE username LIKE '%". realEscape($sendto) ."%' LIMIT 1") or die(mysql_error()); From the code : <?php if(isset($_GET['usercp']) && $_GET['send'] == 'true') { if($_POST['sendtitle'] == "") { echo "You need to have a message title."; } else { if($_POST['sendto'] == "") { echo "You must enter the username of the user you wish to send a message to."; } else { if($_POST['sendtext'] == "") { echo "You have not entered anything to send"; } else { $sendto = str_replace('_', ' ' , $_POST['sendto']); $compose_a = mysql_query("SELECT * FROM users WHERE username LIKE '%". realEscape($sendto) ."%' LIMIT 1") or die(mysql_error()); if(mysql_num_rows($compose_a) >= 1) { While($compose_b = mysql_fetch_array($compose_a)) { $sendto = $compose_b['id']; } mysql_query("INSERT INTO `notifications` (ipaddress, senderid, recieverid, sent, title, text) VALUES ('". $_SERVER['REMOTE_ADDR'] ."', '". $_SESSION['id'] ."', '" . $sendto . "', NOW(), '". htmlspecialchars($_POST['sendtitle']) ."', '". htmlspecialchars($_POST['sendtext']) ."')") or die(mysql_error()); echo "Message has been sent."; } else { echo "The username you entered does not Exist"; } } } } } ?> The $sendto is a username. i want to make it so if a user puts a Uppercase letter or a lowercase letter or a space where a '_' should be. it still matchs whats in the database. if you find a better way of doing this please post it Hi there Im trying to add a search feature to my pagination but with some googling and searching have had no luck and have also had no luck trying myself this is what i have so far Form Code: [Select] <form action="publist.php" method="post"> Search: <input type="text" name="search"> By: <select name="by"> <option value="name" selected="selected">Name</option> <option value="town">Town</option> <option value="county" >County</option> </select> Results Per Page: <select name="perpage"> <option value="10" selected="selected">10</option> <option value="25">25</option> <option value="50" >50</option> </select> <input type="hidden" name="hidden"> <input type="submit" value="Search"> </form> Related code: if(isset($_POST['hidden'])){ $by = $_POST['by']; $search = $_POST['search']; $sql = "SELECT * FROM table WHERE approved = 'Yes' AND '. $by .' = '. $search .' LIMIT $offset, $rowsperpage"; }else{ $sql = "SELECT * FROM table WHERE approved = 'Yes' LIMIT $offset, $rowsperpage"; } $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); while ($list = mysql_fetch_assoc($result)) { echo' <table width="700" border="1"> <tr> <td colspan="3">'. $list['name'] .'</td> </tr> <tr> <td height="24">Town: '. $list['town'] .'</td> <td>County: '. $list['county'] .'</td> <td>Postcode: '. $list['postcode'] .'</td> </tr> <tr> <td>Contact Number: '. $list['phone'] .'</td> <td>Email: '. $list['pubemail'] .'</td> <td><a href="info.php?id='. $list['ID'] .'">More Information</a></td> </tr> </table><br>'; } But when i try the search it comes out blank, Any help would be great Thanks, Blink359 Hi gang, new to posting but I've read the forum on and off. I'm coding a small community and will have a lot of questions for you over time. The first one is about a search function. We'll have users of different nationalities and languages and you will be able to search, only I was thinking there could be a better way. They'll enter those posts through a dropdown list and when you search it you will use checkboxes. I just don't see the results I want when I pick the array for info. Like I have this right now as the form (which is sent to the php page itself as POST): Nationality: <br /> <input type="checkbox"" name="natBox[]" size="30" value="all"/> All<br /> <input type="checkbox"" name="natBox[]" size="30" value="weuro"/> W Europe<br /> <input type="checkbox"" name="natBox[]" size="30" value="eeuro"/> E Europe<br /> <input type="checkbox"" name="natBox[]" size="30" value="wafrica"/> W Africa<br /> And the thing I was doing was to check the boxes with if (isset) and then make the query longer and longer, butI figure there could be a smarter way. Like if I was going to enter 200 countries I can't really check for all can I? After the check (now deleted) it sets the query to this: $query = "SELECT * FROM user_criteria WHERE (age BETWEEN '$ageFr' AND '$ageTo') AND nationality='$nationality'"; ...and the part I don't have now is to pick the array natBox and add every value so @nationality becomes for instance weuro OR wafrica etc. Got a more elegant approach? Once again the php noob returns with another boggle..... I got my client search working, but when it searches the database, it is only searching case sensative, and its not searching partial words. like for example using last names, if i search for Angeleyezz it will find Angeleyezz, but if i search angeleyezz it wont find it, nor will it find it if i search it as angel, ang, eye, etc etc etc. same goes for all fields that i am searching, name, address, telephone number, city, etc. how do i change this? my form code is he Code: [Select] <form method="get" action="search_client_function.php"> <input type="text" name="search_term" value="search"> <input type="submit" name="search" value="search" /> </form> my search_client_function.php code is he Code: [Select] <?php $title = "Search Results"; $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } include('includes/header.php'); mysql_select_db("terra_elegante_operations", $con); $searchfor = $_GET['search_term']; $query = "select * from client_information where concat (account_number,name_first,name_last,address,city,state,zipcode,telephone,telephone_alt,email) like \"%$searchfor%\""; $result = mysql_query($query) or die("Couldn't execute query"); ?> <br /><br /> <table border="2" cellspacing="0" cellpadding="3" width="960" bordercolor="#000000"> <tr bgcolor="#e6e6e6" align="center"> <td><font face="verdana" size="2" color="#000000"><b>Account Number</b></font></td><td><font face="verdana" size="2" color="#000000"><b>First Name</b></font></td><td><font face="verdana" size="2" color="#000000"><b>Last Name</b></font></td><td><font face="verdana" size="2" color="#000000"><b>Address</b></font></td><td><font face="verdana" size="2" color="#000000"><b>City</b></font></td><td><font face="verdana" size="2" color="#000000"><b>State</b></font></td><td><font face="verdana" size="2" color="#000000"><b>Zipcode</b></td><td><font face="verdana" size="2" color="#000000"><b>Telephone #</b></font></td><td><font face="verdana" size="2" color="#000000"><b>Telephone Alt</b></font></td> <?php while($row = mysql_fetch_array($result)) { ?> <tr> <td><font face="verdana" size="1" color="#000000"><?php echo $row['0'] ?></font></td><td><font face="verdana" size="1" color="#000000"><?php echo $row['1'] ?></font></td><td><font face="verdana" size="1" color="#000000"><?php echo $row['2'] ?></font></td><td><font face="verdana" size="1" color="#000000"><?php echo $row['3'] ?></font></td><td><font face="verdana" size="1" color="#000000"><?php echo $row['4'] ?></font></td><td><font face="verdana" size="1" color="#000000"><?php echo $row['5'] ?></font></td><td><font face="verdana" size="1" color="#000000"><?php echo $row['6'] ?></font></td><td><font face="verdana" size="1" color="#000000"><?php echo $row['7'] ?></font></td><td><font face="verdana" size="1" color="#000000"><?php echo $row['8'] ?></font></td> </tr> <?php } ?> </table> <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> <?php include('includes/footer.php'); ?> I know its a bit sloppy, but I'm a php noob =\ this is the only way i could get it to work lol. The issue I am having is that everytime I click the next button, it takes me to the index page. My question is, how do I set up a proper search results link in "href="?page=1"
index.php
<form action="search" method="GET"> <input type="search" name="search" placeholder="Find products, services ..."> <input type="submit" name="submit" value=""> </form>search.php if(isset($_GET['submit']) && !empty($_GET['search'])) { $value = escape(trim(Input::get('search'))); try { // Find out how many items are in the table $q = DB::getInstance()->query("SELECT * FROM records WHERE MATCH(title) AGAINST('$value' IN BOOLEAN MODE)"); $total = $q->count(); // How many items to list per page $limit = 10; // How many pages will there be $pages = ceil($total / $limit); // What page are we currently on? $page = min($pages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array( 'options' => array( 'default' => 1, 'min_range' => 1, ), ))); // Calculate the offset for the query $offset = ($page - 1) * $limit; // Some information to display to the user $start = $offset + 1; $end = min(($offset + $limit), $total); // Prepare the paged query $stmt = DB::getInstance()->query("SELECT users.*, records.* FROM records LEFT JOIN users ON records.user_id = users.user_id WHERE MATCH(title) AGAINST('$value' IN BOOLEAN MODE) ORDER BY relevance DESC LIMIT {$limit} OFFSET ".$offset); if($stmt->count()) { // Display the results foreach($stmt->results() as $row) { $date = escape($row->posted); $record_date = escape(Input::facebook_date_format($date)); $record_id = escape($row->record_id); $title = trim($row->title); $slug_title = $row->slug_title; $view_count = escape(intval(number_format($row->views + 1))); $username = escape($row->username); require 'snippets/record_widget.php'; } } else { ?><div class="message"><?php echo 'No records found.';?></div><?php } <?php // The "back" link $prevlink = ($page > 1) ? '<a href="?page=1" title="First page"><img src="images/left-page-arrow-end.png"/></a> <a href="?page=' . ($page - 1) . '" title="Previous page"><img src="images/left-page-arrow-start.png"/></a>' : '<span class="disabled"><img src="images/left-page-arrow-end-disabled.png"/></span> <span class="disabled"><img src="images/left-page-arrow-start-disabled.png"/></span>'; // The "forward" link $nextlink = ($page < $pages) ? '<a href="?page=' . ($page + 1) . '" title="Next page"><img src="images/right-page-arrow-start.png"/></a> <a href="?page=' . $pages . '" title="Last page"><img src="images/right-page-arrow-end.png"/></a>' : '<span class="disabled"><img src="images/right-page-arrow-start-disabled.png"/></span> <span class="disabled"><img src="images/right-page-arrow-end-disabled.png"/></a></span>'; // Display the paging information ?> <div class="pages"> <span class="pages-arrows"><?php echo $prevlink; ?></span> <span class="pages-numbers"><?php echo $page; ?> of <?php echo $pages; ?></span> <span class="pages-arrows"><?php echo $nextlink; ?></span> </div> } catch (Exception $e) { echo '<p>', $e->getMessage(), '</p>'; } } else { Redirect::to('index'); } Edited by man5, 20 August 2014 - 10:27 PM. 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 Hi all, I'm trying to get a search box and a checkbox to both work at the same time. I have two versions of this code, when I use the first one my checkbox works like it should, filtering out all records with product_type = 3, but the search bar no longer works as it should, filtering things out of three fields defined elsewhere. The bottom code has the search bar working but doesnt incorporate the checkbox as a filter. Thanks for any help! Checkbox works: Code: [Select] $where_filter = ""; if($where != "*"){ foreach($search_map as $search_name){ $where_filter .=" $op $search_name $not REGEXP '$where'"; } $where_filter = substr($where_filter, 5)." AND "; } if ($exclude == "exclude"){ $where_filter .= "product_type!='3'"; $q->addWhere("($where_filter)"); $q->addOrder('product_id'); } Search works: Code: [Select] $where_filter = " "; foreach($search_map as $search_name) $where_filter .=" $op $search_name $not REGEXP '$where'"; $where_filter = substr($where_filter, 5); if($where != "*") $q->addWhere("($where_filter)"); $q->addOrder('product_id'); Hi, i'm currently building essentially an API for my URL shortener site so other sites can implement it. But i've hit a stumbling block on the last script of the lot(the others merely collate the data and store it) In this last script, i need to find all this data, stored in cookies and inout it into the database, as the main site does(i'm confident this bit works, as it's the code from the main site just copied across, and i can see the data in the database). Importantly, i then need o look in another table for the callback URL to send the data back to $urltoshorten = $_COOKIE["URLtoShorten"]; $alias = $_COOKIE["urlalias"]; $key = $_COOKIE["key"]; //connection details go in here $alias =mysql_real_escape_string($alias); $urltoshorten = mysql_real_escape_string($urltoshorten); $base = "http://s-url.co.uk/i/?id="; $url = $base . $alias ; //this is the main bit, where the URL shortening occurs mysql_query("INSERT INTO table (id, name) VALUES('$alias', '$urltoshorten')")or die( mysql_error()); //this is where the callback url is looked for $result= mysql_query("SELECT apiaddress FROM apistuff WHERE apinumber='$key'")or die( mysql_error()); $row = mysql_fetch_array($result); $new = $row[apiaddress]; //I then start a CURL session to POST data to the page in question, as found above $Curl_Session = curl_init($new); curl_setopt ($Curl_Session, CURLOPT_POST, 1); curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, "shortenedurl=$url"); curl_exec ($Curl_Session); curl_close ($Curl_Session); annoyingly, no errors get thrown, as far as i can see, i just end at a blank page without being returned to the callback page. I'm rather stumped on this one, where am i likely to be going wrong/how do i go about correcting it. Cheers Joe The result pages is supposed to have pagination like google help me please
This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=322008.0 |