PHP - Search Checkbox Noob Problem
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? Similar TutorialsAfter a few days of searching and running across a problem what is almost like mine on these forums (cant seem to find the link now) where the person was looking to search a database using checkboxes. What I am trying to do is use a list of checkboxes (http://www.animeseason.com/anime-list/categories/) exactly like this link and search my table which has the genres as columns. I am new to PHP and don't really have a starting point. I have taken a bunch of examples and came up with this. My HTML form with a list of all my checkboxes. Code: [Select] <form method="post" ACTION = "php/do_search.php"> <ul class="cat_col"> <li><input type="checkbox" name="cat_check[]" value="1"> <a href="#Action">Action</a></li> <li><input type="checkbox" name="cat_check[]" value="2"> <a href="#Adventure">Adventure</a></li> <li><input type="checkbox" name="cat_check[]" value="3"> <a href="#Comedy">Comedy</a></li> <li><input type="checkbox" name="cat_check[]" value="4"> <a href="#Demons">Demons</a></li> <li><input type="checkbox" name="cat_check[]" value="5"> <a href="#Drama">Drama</a></li> <li><input type="checkbox" name="cat_check[]" value="6"> <a href="#Ecchi">Ecchi</a></li> <li><input type="checkbox" name="cat_check[]" value="7"> <a href="#Fantasy">Fantasy</a></li> <li><input type="checkbox" name="cat_check[]" value="8"> <a href="#Harem">Harem</a></li> <li><input type="checkbox" name="cat_check[]" value="9"> <a href="#Horror">Horror</a></li> <li><input type="checkbox" name="cat_check[]" value="10"> <a href="#Magic">Magic</a></li> <li><input type="checkbox" name="cat_check[]" value="11"> <a href="#Martial Arts">Martial Arts</a></li> <li><input type="checkbox" name="cat_check[]" value="12"> <a href="#Mecha">Mecha</a></li> <li><input type="checkbox" name="cat_check[]" value="13"> <a href="#Music">Music</a></li> </ul> <ul class="cat_col"> <li><input type="checkbox" name="cat_check[]" value="14"> <a href="#Mystery">Mystery</a></li> <li><input type="checkbox" name="cat_check[]" value="15"> <a href="#Ninja">Ninja</a></li> <li><input type="checkbox" name="cat_check[]" value="16"> <a href="#Parody">Parody</a></li> <li><input type="checkbox" name="cat_check[]" value="17"> <a href="#Psychological">Psychological</a></li> <li><input type="checkbox" name="cat_check[]" value="18"> <a href="#Reverse Harem">Reverse Harem</a></li> <li><input type="checkbox" name="cat_check[]" value="19"> <a href="#Romance">Romance</a></li> <li><input type="checkbox" name="cat_check[]" value="20"> <a href="#Samurai">Samurai</a></li> <li><input type="checkbox" name="cat_check[]" value="21"> <a href="#School Life">School Life</a></li> <li><input type="checkbox" name="cat_check[]" value="22"> <a href="#Science Fiction">Science Fiction</a></li> <li><input type="checkbox" name="cat_check[]" value="23"> <a href="#Seinen">Seinen</a></li> <li><input type="checkbox" name="cat_check[]" value="24"> <a href="#Shoujo">Shoujo</a></li> <li><input type="checkbox" name="cat_check[]" value="25"> <a href="#Shounen">Shounen</a></li> <li><input type="checkbox" name="cat_check[]" value="26"> <a href="#Slapstick">Slapstick</a></li> </ul> <ul class="cat_col"> <li><input type="checkbox" name="cat_check[]" value="27"> <a href="#Slice of Life">Slice of Life</a></li> <li><input type="checkbox" name="cat_check[]" value="28"> <a href="#Sports">Sports</a></li> <li><input type="checkbox" name="cat_check[]" value="29"> <a href="#Supernatural">Supernatural</a></li> <li><input type="checkbox" name="cat_check[]" value="30"> <a href="#Thriller">Thriller</a></li> <li><input type="checkbox" name="cat_check[]" value="31"> <a href="#Tragedy">Tragedy</a></li> <li><input type="checkbox" name="cat_check[]" value="32"> <a href="#Vampire">Vampire</a></li> </ul> <ul class="cat_col"> <li><input type="checkbox" name="cat_check[]" value="33"> <a href="#Movie">Movie</a></li> <li><input type="checkbox" name="cat_check[]" value="34"> <a href="#OVA">OVA</a></li> <li><input type="checkbox" name="cat_check[]" value="35"> <a href="#Top Rated">Top Rated</a></li> <li><input type="checkbox" name="cat_check[]" value="36"> <a href="#Currently Airing">Currently Airing</a></li> <li><input type="checkbox" name="cat_check[]" value="37"> <a href="#Ended">Ended</a></li> <li><input type="checkbox" name="cat_check[]" value="38"> <a href="#Ongoing">Ongoing</a></li> </ul> <div id="submit_btn_pos"> <input type="submit" name="search" value="Lets Make Magic" class="submit_btn"> <> </form> My PHP script that right now seems to do nothing. Code: [Select] <?php //if we got something through $_POST if (isset($_POST['cat_check'])) { $con = mysql_connect("localhost","USERNAME","PASSWORD") or die("Connection error"); mysql_select_db("DATABASENAME")or die("database doesn't exist"); // sanitize user input $cleanData = array(); foreach($_POST['cat_check'] as $_comp) { //$cleanData = mysql_real_escape_query($_comp); } // Build query $compStr = implode("'), ('", $cleanData); $sql = "SELECT anime_name WHERE $_comp='1'"; } ?> My database has a layout of "Name of show, (every genere listed above)". Thanks for any help. Ok so heres the deal, my friend wrote this for me, hes currently unavailable and i messed it up a bit. http://pastebin.com/k937xDve < there is the code. all i did is add the Code: [Select] target="name" onclick="window.open('http://www.web-hosting-service.org/green-certified.php?greensite=.$domain.','name','height=255,width=250,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no'); return false;" bit. and now i get the error Parse error: syntax error, unexpected T_STRING in seal-generator.php It's just a simple question... <?php include ('beginning.txt'); ?> Why can't I include the whole url, eg. ... include ('http://www.mywebsite.com/random/beginning.txt') ... ? It just shows a blank page if I type in the whole url name. I would like to include the file beginning.txt into several pages that are under the folder random. And another question... does it matter if I use ' or ". Some php guides say I should use include ('beginning.txt') some say I should use include ("beginning.txt"). I am using the following piece of code to open a new window when a checkbox is checked... <INPUT type="checkbox" name="name" value="YES" onClick="window.open('/somepage.php?do=something&id=<?php echo $SOMEID["id"] ?>','','width=600,height=350,left=100,top=100,screenX=100,screenY=100')"> The page opens ok when the checkbox is ticked (checked). PROBLEM: The page opens again if the checkbox is un-ticked (un-checked). I just want to open the page if the checkbox is ticked only but not sure how to do this? OTHER INFO: Seperate checkboxes are dynamically created on the page for each id=<?php echo $SOMEID["id"] ?> i have this code: foreach($product_names as $product_row) { ?> <tr> <td > </td><td width='200px'><?php echo $product_row->getName(); ?></td> <td width='200px'><input type="checkbox" name="graphic[]" value="<?php echo $product_row->getId();?>" /></td> <td width='200px'><input type="checkbox" name="text[]" value="<?php echo $product_row->getId();?>" /></td> </tr> <?php } ?> </table> <table> <tr> <td> <input type='hidden' name='submit' value='Submit'> <?php if ( (isset($graphic)) || (isset($text) )) { echo "checkboxes checked"; //show submit button } else { //hide submit botton and echo "no boxes check"; } ?> </td> </tr> </table> so if i want to loop through grapic[] with the code: line 36 $graphics_selected = $_POST['graphic']; line 37 foreach($graphics_selected as $val) { if there is something in array(thus any checkbox is checked) enable submit button else if no checkboxes are checked disable submit button } i get errors: Notice: Undefined index: graphic in /home/helloises/svn_wappool/apps/lpmanager/modules/doc/templates/productSuccess.php on line 36 Warning: Invalid argument supplied for foreach() in /home/helloises/svn_wappool/apps/lpmanager/modules/doc/templates/productSuccess.php on line 37 please help???? Hello, I am trying phpfreaks out without much luck here. If anybody here truly knows how to validate checkboxes as a group please give some assistance. I had to remove the array from the 'name' attribute in my checkbox inputs in order to get the user's checked selections to be properly distributed into separate database columns (not all in one column as a string of text). I am now able to successfully get the entries into the database as "1" for selected and "0" for un-selected. Now however, since there is no array that is holding these input names my validation class method does not work. My validation is suppose to show an error if none of these checkboxes are selected. I had to change each input name to its own identity ( fruit_selection_apple, etc... ), then set my validation like (see code below). However, this is NOT OOP PHP. I had to hard code these values into the validation class. I am also now getting a notice, " Notice: Undefined index: fruit_selection ". Does anyone legitimately know their PHP enough to help with this issue? public function check($source, $items = array()) { foreach($items as $item => $rules) { foreach($rules as $rule => $rule_value) { $value = trim($source[$item]); $item = escape($item); $checkboxvalue = (isset($_POST['fruit_selection_apple'])) || (isset($_POST['fruit_selection_orange'])) || (isset($_POST['fruit_selection_banana'])) || (isset($_POST['fruit_selection_pear'])) || (isset($_POST['fruit_selection_kiwi']) ) if($rule === 'atleastone' && empty($checkboxvalue)) { $this->addError("{$item} You must select at least one checkbox."); } Please bear with me. In an html file there is an <!-- BEGIN poll --> ..... <!-- END poll --> I need to draw a separation hr between all rows escept the first one. I believe I need a counter. Please show me how to do this. Thank you. 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> "; } } } } ?> 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 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 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 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 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 ; 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. 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 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 |