PHP - Function To Search For Replaced Numbers
I' stuck with writing function for searching replaced numbers and would really appreciate if someone can tell me what I'm doing wrong.
My table structure looks like:
CREATE TABLE servis.zamjene_brojeva ( id INT(11) NOT NULL AUTO_INCREMENT, vrijeme TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, pocetni_broj VARCHAR(55) DEFAULT NULL, zamjenski_broj VARCHAR(55) DEFAULT NULL, glavni_broj VARCHAR(55) DEFAULT NULL, postoji_zamjena INT(1) DEFAULT NULL, PRIMARY KEY (id) )My function looks like this: //funkcija za traženje zamjene brojeva function zamjena_broja($kataloski_broj){ //Traženje zamjenskog broja $upit_zamjena = "SELECT pocetni_broj, zamjenski_broj, glavni_broj FROM zamjene_brojeva WHERE glavni_broj = '$kataloski_broj'"; $rezultat_zamjena = mysql_query($upit_zamjena) or die (mysql_error()); $row = mysql_fetch_array($rezultat_zamjena); $kataloski_broj = $row["zamjenski_broj"]; $broj_zamjena = mysql_num_rows($rezultat_zamjena); return $kataloski_broj; //Traženje druge zamjene broja if ($broj_zamjena <> 0) { $upit_zamjena = "SELECT pocetni_broj, zamjenski_broj, glavni_broj FROM zamjene_brojeva WHERE pocetni_broj = '$kataloski_broj'"; $rezultat_zamjena = mysql_query($upit_zamjena) or die (mysql_error()); $broj_zamjena2 = mysql_num_rows($rezultat_zamjena); $row2 = mysql_fetch_array($rezultat_zamjena); $kataloski_broj = $row2["zamjenski_broj"]; return $kataloski_broj; //Traženje treće zamjene if ($broj_zamjena2 <> 0) { $upit_zamjena = "SELECT pocetni_broj, zamjenski_broj, glavni_broj FROM zamjene_brojeva WHERE pocetni_broj = '$kataloski_broj'"; $rezultat_zamjena = mysql_query($upit_zamjena) or die (mysql_error()); $broj_zamjena3 = mysql_num_rows($rezultat_zamjena); $row3 = mysql_fetch_array($rezultat_zamjena); $kataloski_broj = $row3["zamjenski_broj"]; return $kataloski_broj; } } }In pocetni_broj is old number and in glavni_broj is new number. But it can happen that number in glavni_broj is old and I need to search in pocetni_broj to see if there is even newer number and it can happen 5 or 6 times like that. I need to find all the numbers that are connected, but I'm not getting that. What am I doing wrong? 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 have this code i am doing something wrong, i want only letters in the Name search Code: [Select] $query = 'SELECT * FROM apartments INNER JOIN suppliers ON apartments . InternalSupplierID = suppliers . InternalSupplierID WHERE ID LIKE '.$_POST['search'].' OR SupplierID LIKE '.$_POST['search'].' OR Name LIKE \' {^[[:alpha:]]+$}'.$_POST['search'].' {^[[:alpha:]]+$}\''; Hi all How do I modify the below code to search multiple tables in mySQL database? $query = "select * from store_items where description like \"%$trimmed%\" or title like \"%$trimmed%\" or dimensions like \"%$trimmed%\" order by id ASC"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); It is for a search function and I need it to search another table called 'about_text' and 'faq_text' Thanks Pete Hi all, I have a textarea field name brief in my php form. The problem is that users are entering phone numbers and email addresses in this field even though there is dedicated email and phone fields. I want a function to either delete the numbers and emails address automatically on this field or alert the user that numbers are not allowed in this field. I have include my form. Many thanks for your help Here is what I'm working with. what is working is the BOLD RED in the code is what is taking my drop down selection and placing it in the search text field. Here is my code <center> <table cellpadding="5" cellspacing="1" class="searchBox"> <tr> <td align="center"> <form action="search.php" method="get"> <table><tr><td> <div align="left"> <input type="text" name="query" id="query" size="40" value="<?php print quote_replace($query);?>" action="include/js_suggest/suggest.php" columns="2" autocomplete="off" delay="1500"> <form action="" method ="post"> <p> <select name="state" onchange="document.getElementById('query').value=this.value;"> <option value="Nation Wide"> Nation Wide </option> <option value="Nation Wide ex AK/HI"> Nation Wide ex AK & HI </option> <option value="Alabama"> Alabama </option> <option value="Alaska"> Alaska </option> <option value="Arizona"> Arizona </option> <option value="Arkansas"> Arkansas </option> <option value="California"> California </option> <option value="Colorado"> Colorado </option> <option value="Connecticut"> Connecticut </option> <option value="Deleware"> Deleware </option> <option value="Florida"> Florida </option> <option value="Georgia"> Georgia </option> <option value="Hawaii"> Hawaii </option> <option value="Idaho"> Idaho </option> <option value="Illinois"> Illinois </option> <option value="Indiana"> Indiana </option> <option value="Iowa"> Iowa </option> <option value="Kansas"> Kansas </option> <option value="Kentucky"> Kentucky </option> <option value="Louisiana"> Louisiana </option> <option value="Maine"> Maine </option> <option value="Maryland"> Maryland </option> <option value="Massachusetts"> Massachusetts </option> <option value="Michigan"> Michigan </option> <option value="Minnesota"> Minnesota </option> <option value="Mississippi"> Mississippi </option> <option value="Missouri"> Missouri </option> <option value="Montana"> Montana </option> <option value="Nebraska"> Nebraska </option> <option value="Nevada"> Nevada </option> <option value="New Hampshire"> New Hampshire </option> <option value="New Jersey"> New Jersey </option> <option value="New Mexico"> New Mexico </option> <option value="New York"> New York </option> <option value="North Carolina"> North Carolina </option> <option value="North Dakota"> North Dakota </option> <option value="Ohio"> Ohio </option> <option value="Oklahoma"> Oklahoma </option> <option value="Oregon"> Oregon </option> <option value="Pennsylvania"> Pennsylvania </option> <option value="Rhode Island"> Rhode Island </option> <option value="South Carolina"> South Carolina </option> <option value="South Dakota"> South Dakota </option> <option value="Tennessee"> Tennessee </option> <option value="Texas"> Texas </option> <option value="Utah"> Utah </option> <option value="Vermont"> Vermont </option> <option value="Virginia"> Virginia </option> <option value="Washington"> Washington </option> <option value="West Virginia"> West Virginia </option> <option value="Wisconsin"> Wisconsin </option> <option value="Wyoming"> Wyoming </option> </select> <select name="prop" onchange="document.getElementById('query').value=this.value;"> <option value="Downtown or Streetfront"> Downtown or Streetfront </option> <option value="Freestanding Pad"> Freestanding Pad </option> <option value="Lifestyle Center"> Lifestyle Center </option> <option value="Mall or Food Court"> Mall or Food Court </option> <option value="Nontraditional Units"> Nontraditional Units </option> <option value="Power Center"> Power Center </option> <option value="Shopping Center"> Shopping Center </option> <option value="Entertainment Center"> Entertainment Center </option> <option value="Manufacturer Outlet Center"> Manafacturer Outlet Center </option> <option value="Regional Mall"> Regional Mall </option> </select> <input type="submit" name="submit" value="search"> </p> </form> </div> <td> </td></tr></table> <?php if ($adv==1 || $advanced_search==1) { ?> <table width = "100%"> <tr> <td width="40%"><input type="radio" name="type" value="and" <?php print $type=='and'?'checked':''?>><?php print $sph_messages['andSearch']?></td> <td><input type="radio" name="type" value="or" <?php print $_REQUEST['type']=='or'?'checked':''?>><?php print $sph_messages['orSearch']?></td></tr> <tr> <td><input type="radio" name="type" value="phrase" <?php print $_REQUEST['type']=='phrase'?'checked':''?>><?php print $sph_messages['phraseSearch']?></td> <td><?php print $sph_messages['show']?> <select name='results'> <option <?php if ($results_per_page==10) echo "selected";?>>10</option> <option <?php if ($results_per_page==20) echo "selected";?>>20</option> <option <?php if ($results_per_page==50) echo "selected";?>>50</option> <option <?php if ($results_per_page==100) echo "selected";?>>100</option> </select> <?php print $sph_messages['resultsPerPage']?> </td> </tr> </table> <?php }?> <?php if ($catid<>0){?> <center><b><?php print $sph_messages['Search']?></b>: <input type="radio" name="category" value="<?php print $catid?>"><?php print $sph_messages['Only in category']?> "<?php print $tpl_['category'][0]['category']?>'" <input type="radio" name="category" value="-1" checked><?php print $sph_messages['All sites']?></center> <?php }?> <input type="hidden" name="search" value="1"> </form> <?php if ($has_categories && $search==1 && $show_categories){?> <a href="search.php"><?php print $sph_messages['Categories']?></a> <?php }?> </td> </tr> </table> </center> I need help with understanding how to..... 1. Apply both drop downs to the search without erasing first one. 2. Separate by ( ) A SPACE Any ideas and or help would be great. Thanks in advance I have a form where there are various fields one can edit and replace images as well. The problem is when one tries to replace the image they choose. It only replaces the path of the file on column "imageurl1" on the MySQL database and not on the one that was chosen. I'm also getting a "Invalid argument supplied for foreach()" Here is the script Code: [Select] <?php session_start(); include('SimpleImage.php'); $image = new SimpleImage(); //error_reporting(E_ALL); // image upload folder $image_folder = 'images/classified/'; // fieldnames in form $all_file_fields = array('image1', 'image2' ,'image3', 'image4', 'image5', 'image6', 'image7', 'image8', 'image9', 'image10', 'image11', 'image12'); // allowed filetypes $file_types = array('jpg','gif','png'); // max filesize 5mb $max_size = 5000000; //echo'<pre>';print_r($_FILES);exit; $time = time(); $count = 1; foreach($all_file_fields as $fieldname){ if($_FILES[$fieldname]['name'] != ''){ $type = substr($_FILES[$fieldname]['name'], -3, 3); // check filetype if(in_array(strtolower($type), $file_types)){ //check filesize if($_FILES[$fieldname]['size']>$max_size){ $error = "File too big. Max filesize is ".$max_size." MB"; }else{ // new filename $filename = str_replace(' ','',$myusername).'_'.$time.'_'.$count.'.'.$type; // move/upload file $image->load($_FILES[$fieldname]['tmp_name']); if($image->getWidth() > 150) { //if the image is larger that 150. $image->resizeToWidth(500); //resize to 500. } $target_path = $image_folder.basename($filename); //image path. $image->save($target_path); //save image to a directory. //save array with filenames $images[$count] = $image_folder.$filename; $count = $count+1; }//end if }else{ $error = "Please use jpg, gif, png files"; }//end if }//end if }//end foreach if($error != ''){ echo $error; }else{ //error_reporting(E_ALL); //ini_set('display_errors','On'); $id = $_POST['id']; $id = substr($id, 0,5); if($id < 1 || $id > 99999) exit; $servername = "localhost"; $username = ""; $password = ""; if(!$_POST["title"] || !$_POST["rent"] || !$_POST["fees"]){ header('location: fields.php'); }else if (!(preg_match('#^\d+(\.(\d{2}))?$#',($_POST["rent"])))){ header('location: rent.php'); }else{ $conn = mysql_connect($servername,$username,$password)or die(mysql_error()); mysql_select_db("apts",$conn); // validate id belongs to user $sql_check = "SELECT * FROM apts WHERE id = '".$id."' AND username = '".$myusername."'"; $res = mysql_query($sql_check,$conn) or die(mysql_error()); $count = mysql_num_rows($res); if ($count > 0){ $sql_images = ""; foreach($images as $number => $imagedetail){ if($imagedetail != ''){ $sql_images .= "imageurl".$number." = '".mysql_real_escape_string($imagedetail)."',"; } } $sql = "UPDATE apartments SET title = '".mysql_real_escape_string($_POST['title'])."', description = '".mysql_real_escape_string($_POST['description'])."', cross_streets = '".mysql_real_escape_string($_POST['cross_streets'])."', county = '".mysql_real_escape_string($_POST['county'])."', town = '".mysql_real_escape_string($_POST['town'])."', service = '".mysql_real_escape_string($_POST['service'])."', phone = '".mysql_real_escape_string($_POST['phone'])."', contact = '".mysql_real_escape_string($_POST['contact'])."', office = '".mysql_real_escape_string($_POST['office'])."', pets = '".mysql_real_escape_string($_POST['pets'])."', email = '".mysql_real_escape_string($_POST['email'])."', rooms = '".mysql_real_escape_string($_POST['rooms'])."', bath = '".mysql_real_escape_string($_POST['bath'])."', square = '".mysql_real_escape_string($_POST['square'])."', rent = '".mysql_real_escape_string($_POST['rent'])."', fees = '".mysql_real_escape_string($_POST['fees'])."', service = '".mysql_real_escape_string($_POST['service'])."', feeornofee = '".mysql_real_escape_string($_POST['feeornofee'])."', lease = '".mysql_real_escape_string($_POST['lease'])."', video= '".mysql_real_escape_string($_POST['video'])."', zipcode = '".mysql_real_escape_string($_POST['zipcode'])."',".$sql_images." videotitle = '".mysql_real_escape_string($_POST['videotitle'])."' WHERE id = '".$id."'"; //replace info with the table name above $result = mysql_query($sql,$conn) or die(mysql_error()); header('location: apartments.php'); }else{ header('location: somethingwrong.php'); } } } ?> Hello Happy Campers.
Wonder if someone can point me in the right direction if it's not too much trouble.
I have a script that allows an EU to edit a database entry. The users edits the information and hits submit which then edits the content and it all works spiffingly.
My problem however arises when I go to upload a new image.
The "Add" function uploads images to a directory and the location is saved in the database.
When editing the image however, it unlinks it but it does not allow me to upload a new image.
The code is as follows:
ini_set('display_errors',1); error_reporting(E_ALL); $conn = mysqli_connect("HOST","DB","PWRD","DBTBL") or die('Cannot Connect to the database'); $i = mysqli_real_escape_string($conn,$_POST['newsid']); $t = mysqli_real_escape_string($conn,$_POST['title']); $st = mysqli_real_escape_string($conn,$_POST['stat']); $sn = mysqli_real_escape_string($conn,$_POST['snip']); $s = mysqli_real_escape_string($conn,$_POST['stry']); $c = mysqli_real_escape_string($conn,$_POST['cap']); $f = $_POST['oldim']; $s = nl2br($s); if(!is_uploaded_file($_FILES['file']['tmp_name'])) { $naquery = "UPDATE news SET newstitle='$t',newssnip='$sn',newsarticle='$s',newsstatus='$st' WHERE newsid=$i"; } else { if ($_FILES['file']['type'] != "image/gif" && $_FILES['file']['type'] != "image/jpeg" && $_FILES['file']['type'] != "image/jpg" && $_FILES['file']['type'] != "image/x-png" && $_FILES['file']['type'] != "image/png") { $naquery = "UPDATE news SET newstitle='$t',newssnip='$sn',newsarticle='$s',newsstatus='$st' WHERE newsid=$i"; } else { $finame = $_FILES["file"]["name"]; $result = move_uploaded_file($_FILES['file']['tmp_name'], "../news/$finame"); if ($result == 1) { $naquery = "UPDATE news SET newstitle='$t',newssnip='$sn',newsarticle='$s',newsimage='$finame' newscaption='$c',newsstatus='$st' WHERE newsid=$i"; $d = "../news/"; unlink("$d$f"); } else { $naquery = "UPDATE news SET newstitle='$t',newssnip='$sn',newsarticle='$s',newsstatus='$st' WHERE newsid=$i"; } } } $result = mysqli_query($conn, $naquery); if($result){ header('Location: ../news.php'); } else { echo "Oh No! Something has gone wrong and the data could not be uploaded"; echo "<br />"; echo "click <a href='Link'>here</a> to return to News"; } mysqli_close($conn);I am not getting an error message from PHP, I am just getting the generic "Something has gone wrong" that I have coded in myself. Is there anyone who can point me in the right direction please? Cheers Hi, I have a "user profile" page and it has a profile image upload form. I have it so that the old profile image is deleted, and the new image is uploaded and the new image is echoed out using the name of the new file from the database. The problem is, when I click submit to add the new image, the old image still stays there and the new image does not show up. Only when I manually click refresh on my browser does the new image show up. That is going to be bad for my users. Please if anyone can help, I'd greatly appreciate it. Below is the code I am using to delete the old image, and code to upload the image as well, when the photo upload form is used. Code: [Select] if(isset($_POST['photoUpload'])) { if(file_exists("images/".$currentUser.".jpg")){ unlink("images/".$currentUser.".jpg"); clearstatcache(); } //reads the name of the file the user submitted for uploading $image=$_FILES['image']['name']; //if it is not empty if ($image) { //get the original name of the file from the clients machine $filename = stripslashes($_FILES['image']['name']); //get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strtolower($extension); //if it is not a known extension, we will suppose it is an error and will not upload the file, //otherwise we will do more tests if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { //print error message echo '<h1>Unknown extension!</h1>'; $errors=1; } } //end if here //was else here //get the size of the image in bytes //$_FILES['image']['tmp_name'] is the temporary filename of the file //in which the uploaded file was stored on the server $size=filesize($_FILES['image']['tmp_name']); //compare the size with the maxim size we defined and print error if bigger if ($size > MAX_SIZE*1024) { echo '<h1>You have exceeded the size limit!</h1>'; $errors=1; } //we will give an unique name, for example the time in unix time format $image_name= $currentUser .'.'.$extension; //$image_name=time().'.'.$extension; //the new name will be containing the full path where will be stored (images folder) $newname=$image_name; //"images/". // Connects to your Database mysql_connect("host", "user", "pass") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()) ; //we verify if the image has been uploaded, and print error instead $copied = copy($_FILES['image']['tmp_name'], "images/".$newname); // update the photo name in the database $result = mysql_query("UPDATE users SET profilePhoto='$newname' WHERE username='$currentUser'") or die(mysql_error()); if (!$copied) { echo '<h1>Copy unsuccessful!</h1>'; $errors=1; } else{ $dir="images/"; echo "<p>Profile Picture Change Successful!</p>"; echo "<img src='{$dir}{$newname}' alt='{$newname}' height='200' width='200' />"; echo "<p></p>"; } } I have been using this code which i found on here which I have gotten to work with my website but I would just like to know how I can make it so that when I click the search button it can take me to a new page which will show the results in a table. Code: [Select] <?php // Set up our error check and result check array $error = array(); $results = array(); // First check if a form was submitted. // Since this is a search we will use $_GET if (isset($_GET['search'])) { $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 3) { $error[] = "Search terms must be longer than 3 characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } // If there are no errors, lets get the search going. if (count($error) < 1) { $searchSQL = "SELECT id, product_name, product_price, product_description FROM product WHERE "; // grab the search types. $types = array(); $types[] = isset($_GET['name'])?"`product_name` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['price'])?"`product_price` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['description'])?"`product_description` LIKE '%{$searchTermDB}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) $types[] = "`product_name` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked $andOr = isset($_GET['matchall'])?'AND':'OR'; $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `product_name`"; // order by title. $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "The search term provided {$searchTerms} yielded no results."; }else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$i}: {$row['product_name']}<br />{$row['product_price']}<br />{$row['product_description']}<br /><br />"; $i++; } } } } <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="get" name="searchForm" id="searchForm"> Search For: <input type="text" name="search" value="<?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?>" /> <br /> <br /> <input type="submit" name="submit" value="Search!" /> </form> <?php echo (count($results) > 0)?"Your search term: {$searchTerms} returned:<br /><br />" . implode("", $results):""; ?> I would be very grateful if someone could help me to get this done. Edit (KP): Next time, please use code tags. Ok i have seen many solutions for using a search function to post onto webpage directly from the mysql db but my question is
is there a way to seach the results that were already outputted via a php query, for instance i have a query that returns
1 MisFit_Kay1 811 2 sajoma 806 3 Atlfan 708 4 karlsbad70 633 5 Booo 570 6 MisFit_Mimi_shg 541 7 PRO_Viking 540 8 tm7_cryzal 540 9 TM7__mina 499 10 PRO_DRFRANK 488 11 PRO_FLAK 488 12 Mhoram 464 13 TM7__CEDAR 462 14 ProSultan 456 15 UBG_Steely1 450but with lots more results now what im hoping for is a point in a direction where i could add a search box that will highlight the name from the list provided . any help will be appreciated Edited by Justafriend, 20 October 2014 - 01:56 AM. hi im just trying to do a search on a database and display results based on what the user selected: form code: Code: [Select] html> <body> <form action="search.php" method="POST"> Type of property: <select name="Type_of_Property"> <option>Terraced</option> <option>Detached</option> <option>Semi-Detached</option> <option>Bungalow</option> <option>Flat </option> </select> <p><input type="submit" value="Send Details" name="B1"></p> </form> php code: Code: [Select] <html> <body> <?php error_reporting(E_ALL); mysql_connect("localhost", "root") or die(mysql_error()); // makes a connection mysql_select_db("estate_agents") or die('I cannot connect to the database because: ' . mysql_error()); //conects to the database $result = mysql_query("SELECT * FROM properties WHERE Type_of_Property ='".$_POST['Type_of_Property']); echo "<table border=1>\n"; echo "<tr><td>Address 1</td><td>Address 2</td><td>Postcode</td><td>Type of Property</td><td>Number of Bedrooms</td><td>Number of Bathrooms</td></tr>\n"; while ($row = mysql_fetch_row($result)) { } print "Data base updated with: " .$_POST["Type_of_Property"] ; ?> </body> </html> the propbelm im having is being able to display the results in the table in the while loop any help is appreciated thank you Hi guys! I want to improve the search function of a wordpress site with AliPlugin. The products shown are completely off topic, you have to be very accurate to get what you need, if you are too accurate of course, you will get nothing.
The site is: http://www.beta.cfcbazar.com Its the site for testing.
Can anyone help me please? Hi, im trying to do a search function that will search through the database Examples : table game with id, name I want to get the ID by searching with keywords BUT my keywords is like 'battle field' and I search only 'battle' How do I get battle field ID from the database with just 'battle' ? Please help me out or show me tutorials. thanks. Won't let me type in this box more then 1 line . See Post 3,4 Thanks This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=346179.0 So I have a basic search form that goes through and does a mySQL like '%$sanitizedInput%' to column in the table. The problem I have is that if I have two rows, one with a value "green" and the second "blue", and I do a search for "green", it shows the green result, if I do a search for "blue", it shows the blue result, but if i do a search for "green blue" it returns no results. Any ideas on how to fix this? I was showing a friend what I've been working on, and as I watched him type in an entry to search - then not get a result that I know was indeed in the database I realized I needed to accommodate "user laziness." He didn't use punctuation. So I'm trying to figure out how to make that a nonfactor in searches. In other words, my database may have an entry called "St. Patrick's Cathedral" If somebody types "st patricks cathedral" I want the result to still show up. Here's what I'm using right now: Code: [Select] if(isset($_POST[submitted])) { $item = $_REQUEST['find']; $filter1 = trim($_POST['filter1']); if ($filter1 == 'sci-names') { $data = mysql_query("SELECT * FROM table WHERE CONCAT(taxonomic_genus,' ',scientific_name) LIKE '%$item%'"); Hi, I am trying to build a search function and so far I have it working with just one DB field but I need it to search for different fields. This is my search form: Code: [Select] <form action="t_articulo_Results.php" method="get" name="SearchForm" id="SearchForm"> <label> <input type="text" name="S_articulo_esp" id="S_articulo_esp" value="search" size="30" /> <input type="hidden" name="Search" id="Search" value="Buscar" /> </label> </form> where the field "S_articulo_esp" is a text field to enter the search criteria. This is the code on my results page inclung query: Code: [Select] <?php $MySearch_DefaultWhere = ""; if (!session_id()) session_start(); if ((isset($_GET["Search"]) && $_GET["Search"] != "")) { $MySearch = new FilterDef; $MySearch->initializeQueryBuilder("MYSQL","1"); //keyword array declarations //comparison list additions $MySearch->addComparisonFromEdit("company_name","S_articulo_esp","AND","Includes",0); //save the query in a session variable if (1 == 1) { $_SESSION["MySearch_t_articulo_Results"]=$MySearch->whereClause; } } else { $MySearch = new FilterDef; $MySearch->initializeQueryBuilder("MYSQL","1"); //get the filter definition from a session variable if (1 == 1) { if (isset($_SESSION["MySearch_t_articulo_Results"]) && $_SESSION["MySearch_t_articulo_Results"] != "") { $MySearch->whereClause = $_SESSION["MySearch_t_articulo_Results"]; } else { $MySearch->whereClause = $MySearch_DefaultWhere; } } else { $MySearch->whereClause = $MySearch_DefaultWhere; } } $MySearch->whereClause = str_replace("\\''", "''", $MySearch->whereClause); $MySearchwhereClause = ''; ?> <?php $maxRows_RecordSett_articulo = 10; $pageNum_RecordSett_articulo = 0; if (isset($_GET['pageNum_RecordSett_articulo'])) { $pageNum_RecordSett_articulo = $_GET['pageNum_RecordSett_articulo']; } $startRow_RecordSett_articulo = $pageNum_RecordSett_articulo * $maxRows_RecordSett_articulo; mysql_select_db($database_MySQLconnect, $MySQLconnect); $query_RecordSett_articulo = "SELECT id_cliente, company_name, cliente_calle, cliente_numero, cliente_local, cliente_poblacion, cliente_cp, cliente_pais, cliente_tel, cliente_fax, cliente_movil, cliente_personadecontacto, cliente_email, cliente_web FROM t_clientes ORDER BY company_name ASC"; setQueryBuilderSource($query_RecordSett_articulo,$WADbSearch1,false); $query_limit_RecordSett_articulo = sprintf("%s LIMIT %d, %d", $query_RecordSett_articulo, $startRow_RecordSett_articulo, $maxRows_RecordSett_articulo); $RecordSett_articulo = mysql_query($query_limit_RecordSett_articulo, $MySQLconnect) or die(mysql_error()); $row_RecordSett_articulo = mysql_fetch_assoc($RecordSett_articulo); if (isset($_GET['totalRows_RecordSett_articulo'])) { $totalRows_RecordSett_articulo = $_GET['totalRows_RecordSett_articulo']; } else { $all_RecordSett_articulo = mysql_query($query_RecordSett_articulo); $totalRows_RecordSett_articulo = mysql_num_rows($all_RecordSett_articulo); } $totalPages_RecordSett_articulo = ceil($totalRows_RecordSett_articulo/$maxRows_RecordSett_articulo)-1; ?> please note this line Code: [Select] $MySearch->addComparisonFromEdit("company_name","S_articulo_esp","AND","Includes",0);//comparison list additions because here is where I am getting confused . How can I add more fields to it? Thanks <script type="text/javascript"> function listBoxSearch(){ var input = document.getElementById('searchBox'), output = document.getElementById('listBoxF'); if(input.value != ''){ for (var i = 0; i < output.options.length; i++){ if(output.options[i].text.substring(0, input.value.length).toUpperCase() == input.value.toUpperCase()){ output.options[output.options.length] = new Option(output.options[i].innerHTML, output.options[i].text); } } if (output.options.length == 1) { output.selectedIndex = 0; } } } </script>It dosen`t work. It should work like this[DEMO in attached filed] Attached Files listbox_with_keybord_search.htm 7.9KB 3 downloads |