PHP - Php Search And Replace Problem
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 Similar TutorialsThe situation is that I have a large string with some identifiers to say "replace me" with something else. My goal is to replace the values, but if one replacement includes one of the other keys, I don't want to replace it.
For example:
<?php $str = 'some blob ~abc~ followed by ~def~'; $arr_orig = array( '~abc~', '~def~' ); $arr_new = array( 'value~def~', 'blah' ); echo str_replace( $arr_orig, $arr_new, $str ); ?>This will echo: some blob valueblah followed by blah But that's not what I'm trying to accomplish. Basically, I want ~abc~ to be replaced with the literal: value~def~ and for the ~def~ that happens to be part of that string to NOT be replaced. I hope what I'm asking is clear. Basically, preg_replace/str_replace with arrays seems no different than just doing a FOR loop and replacing ~abc~ and then ~def~. But that's not what I need. I'm hoping that if ~abc~ is replaced with text that happens to be another identifier -- ~def~, ~xyz~, whatever -- that this already replaced text is not again replaced. Is there a built-in function to do something like this? If not, should I just parse the whole string and count characters or something? Seems like a pain (and slow!) I can' t even get the simple str_replace to work. I got.... $rslt = $client->getTodaySubIDStats($key, $sub_id); $rslt = str_replace("EARNINGS",'',$rslt); $rslt = str_replace("Array","",$rslt); $rslt = str_replace("\r","",$rslt); $rslt = str_replace("\n","",$rslt); $rslt = str_replace("\t","",$rslt); print_r($rslt); which spits out.... Code: [Select] Array ( [0] => Array ( [EARNINGS] => $100.40 [CLICKS] => 1301 [LEADS] => 100 [SUB_ID] => yacker [EPC] => $0.11 ) ) I would like to have every thing removed except the '$100.40' (The number is always changing). Then remove the $ and do math 100.40*.40, so in the end, all it spits out is 40.16 and always only have two digits after the period. $file=str_replace("{title2}",$line['title'],$file); $file['title2'] = trim(preg_replace('/[^\w\d]+/', ' ', $file['title2'])); $file['title2'] = str_replace(' ', '-', $file['title2']); The first line does what it should do, have {title2} in the template generate the page title. The next two lines don't do the replacing. Hi everyone!! I just started learning PHP two weeks ago and I hope someone can help me!! I need to do a find and replace on a string, and each replace needs to have an unique id, and if that unique id exists in a table then return the value on the table. Make sense? So like "find all the Xs in the string, replace with "X1, X2, X3...", then if "X3' exists on TableB, return value "X3 is on the table and has a value of Y3". I actually got this to work already but it takes a long time to do it so I'm hoping someone could give me some advice on how to make it more EFFICIENT: // PART ONE, find all "X" and replace with unique_id for ($count = 1; $count <= strlen($string); $count++) // do this loop as many times as there are characters in $string { $unique_id = "replacement_" . $count; // give each replacement an unique id (replacement_1, replacement_2, replacement_3, etc..) $string = preg_replace("X", $unique_id, $string , 1); // find X and replace it with the $unique_id in $string, and only do this ONCE } $count_replacements = substr_count($string,"replacement_"); // count how many replacements occured in total // PART TWO, find all unique_ids in tableB and echo the unique_id_value for ($count = 1; $count <= $count_replacements; $count++) // do this loop as many times as there were replacements { $unique_id = "replacement_" . $count; // set the unique_id of each replacement $show_tableB = mysqli_query($link, 'SELECT * FROM tableB'); // select the unique_ids and the unique_id_values in TableB while ($row = mysqli_fetch_array($show_tableB)) { $tableBs[] = array('unique_id' => $row['unique_id'], 'unique_id_value' => $row['unique_id_value']); } foreach($tableBs as $tableB): // for each entry in TableB, if the unique_id in TableB matches the unique_id of the replacement, return the unique_id_value if ($tableB['unique_id'] == $unique_id) { echo $unique_id . " is on TableB and it has a value of ". $tableB['unique_id_value'] } endforeach; } The problem with this is: its not very efficient. If $string has 500 charachters, it does the "PART ONE" 500 times. Then, say it found 300 Xs, it does "PART TWO" 300 more times. And every time it does "PART TWO", it checks all entries in TableB (which could be 200 or more). So, that's it. Anyone has a better idea of how to do this?? Thanks!!!! Hey guys i am trying to search all href in a string and add someting in front so i can catch some stats before i redirect the user. For exemple : href="http://twitter.com" Should be changed into: http://test.ca?dat='.urlencode("http://twitter.com").' But i can't get it to work ... so what i got so fare is <?php $str = "<a target='_blank' href='http://twitter.com'>TEST 1</a> <a target='_blank' href='http://twitter.com'>TEST 2</a>"; $str .= ' <a href="http://twitter.com">TEST 1</a> <a href="http://twitter.com">TEST 2</a>'; function matche($matches){ $url = str_replace('http://', '', $matches[1]); $url = str_replace('www.', '', $url); return 'href="http://test.ca?email=XX_EMAIL&nid=XX_ID&dat='.urlencode($url).'"'; } echo preg_replace_callback("/href=['\"]([.*]+)['\"]/","matche",$str); ?> Hi, I am having a pretty difficult time getting files to upload to my server that have a Single Quote in the file name. Example: myfile's.pdf I need to strip the file name of the quote before it uploads to the server. I currently am using SWFUpload and this is the bit of code that was included with it. I need to modify it to remove the single quotes as well. Been hammering my head over this all day. $file_name = preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name'])); if (strlen($file_name) == 0 || strlen($file_name) > $MAX_FILENAME_LENGTH) { HandleError("Invalid file name"); exit(0); } thanks Hi i wrote a find and replace code but my code replace last value of array and skip the first, second.... values in the array. Please give me an idea because i stack with this code. Regards $KeyWord = explode("\n", $RowGetWords['KEYWORDS']); $Replace = explode("\n", $RowGetWords['ReplaceTo']); for($i=0; $i<count($KeyWord); $i++){ $pattern = $KeyWord[$i]; $replace = "<a href=\"" .$URL. "\" target=\"_blank\" >" .$Replace[$i]. "</a>"; $html = str_replace($pattern, $replace, $Row['MessageBody']); } 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> "; } } } } ?> 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 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 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? 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. 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 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 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 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. |