Jump to content

HowdeeDoodee

Members
  • Posts

    118
  • Joined

  • Last visited

    Never

Everything posted by HowdeeDoodee

  1. In this line, $Topic has a value because $Topic picks up a value from the database and prints the value to the screen. echo "Topic == ",$Topic; These lines...were included in the first post to show you what works. You should not imply that these variables pick up their value from statements like the one below. The $term variables in the actual working code pick up their values from the explode sequence posted above. //$term[0] = 'John Doe'; //$term[1] = 'Jane Smith'; //$term[2] = 'Bill Bobbins'; //$term[3] = 'most'; //$term[4] = 'points'; //$term[5] = 'game'; //$term[6] = 'users'; //$Topic = "<p>The users with the most points in this game were John Doe, Jane Smith, and Bill Bobbins.</p>"; Thank you for the comments.
  2. Thank you for the replies. The input comes into script and is exploded below if ($trimmed == "" | !isset($var)) { echo "<h" . $hlevel . ">Error! No valid search term was entered.</h" . $hlevel . ">"; $skip = TRUE; } if (ereg(" AND | and | And | aND | AnD | anD ",$trimmed,$matches)) { $burst = $matches[0]; $terms = explode($burst,$trimmed); $boolean = TRUE; $split = "AND"; } elseif (ereg(" OR | or | Or | oR ",$trimmed, $matches)) { $burst = $matches[0]; $terms = explode($burst,$trimmed); $boolean = TRUE; $split = "OR"; } $query and $query2 are identical. $query2 is used to develop content for printing to the screen. if (($boolean == TRUE) && ($split == "OR")) { $query2 = "SELECT * FROM `View2_ConcordFT` WHERE MATCH(`Topic`, `Subtopic`, `Theswords`) AGAINST ('$terms[0] $terms[1] $terms[2] $terms[3] $terms[4] $terms[5]' IN BOOLEAN MODE) ORDER BY `Lnum` ASC LIMIT $startrecord, $display"; } elseif (($boolean == TRUE) && ($split == "AND")) { // Boolean AND query - searches for $terms[0] and $terms[1] where both $query2 = "SELECT * FROM `View2_ConcordFT` WHERE MATCH(`Topic`, `Subtopic`, `Theswords`) AGAINST ('+$terms[0] +$terms[1] +$terms[2] +$terms[3] +$terms[4] +$terms[5]' IN BOOLEAN MODE) ORDER BY `Lnum` ASC LIMIT $startrecord, $display"; } else { $query2 = "select * from `View2_Concord` where " . presentedCode($SeeAlso,$searchtype) . " AND `Source` IN ($NV, $TR, $BT) ORDER BY `Lnum` ASC LIMIT $startrecord, $display"; } Retrieve the data from the database using while(list and fill the $variables with the data from the database. $Source="Source"; $Topic="Topic"; $Subtopic="Subtopic"; $References="References"; while(list($Source, $Topic,$Subtopic,$References)= mysql_fetch_row($result2)) { if ($colorcounter == 0) { $colorbg = "#d8e0f0"; } else { $colorbg = "#e6eaf4"; $colorcounter = $colorcounter - 2; } The variable $Topic has a value just prior to being made equal to the $string variable.
  3. If I uncomment the code below starting with //$term[0] and run the code, everything works as it should. All the words in the $term array are highlighted as they should be. However, if i run the code as it is shown here and pick up the $Topic values from the database, no highlighting takes place and I get a Resource id #2 in the Topic field even though the $Topic variable passed to this code is appropriate. Now, the value of $Topic as printed out on the screen is for example, Armies and not 'Armies'. If the missing single quote is the reason I am getting an error, how do I an a single quote to either side of the $Topic variable? //$term[0] = 'John Doe'; //$term[1] = 'Jane Smith'; //$term[2] = 'Bill Bobbins'; //$term[3] = 'most'; //$term[4] = 'points'; //$term[5] = 'game'; //$term[6] = 'users'; //$Topic = "<p>The users with the most points in this game were John Doe, Jane Smith, and Bill Bobbins.</p>"; echo "Topic == ",$Topic; $string = $Topic; $term = array($term[0], $term[1],$term[2],$term[3],$term[4],$term[5],$term[6],); $bgcolor = "yellow"; foreach($term as $value) { $count++; if(!empty($value)) { $replaceWith = "<span style=\"background-color:$bgcolor;\">" . $value . "</span>"; if($count==1) { $result = eregi_replace($value, $replaceWith, $string); } else { $result = eregi_replace($value, $replaceWith, $result); } } } //echo $result; $Topic = $result;
  4. The database has 6 fields, Source, Topic, Subtopic, References, Theswords, and id. I am getting "resource id #3" in every Topic field display when I use this Select statement for Full Text Boolean. If I use a regular Select statement without a Boolean input, the script works fine. Does anyone have any idea what might be going on? Thank you in advance for any replies. $query = "SELECT * FROM `Table2_CordFT` WHERE MATCH(`Topic`, `Subtopic`, `Theswords`) AGAINST ('+$terms[0] +$terms[1] +$terms[2] +$terms[3] +$terms[4] +$terms[5]' IN BOOLEAN MODE) ORDER BY `Lnum` ASC "; } elseif (($boolean == TRUE) && ($split == "AND")) { $query = "SELECT * FROM `Table2_CordFT` WHERE MATCH(`Topic`, `Subtopic`, `Theswords`) AGAINST ('+$terms[0] +$terms[1] +$terms[2] +$terms[3] +$terms[4] +$terms[5]' IN BOOLEAN MODE) ORDER BY `Lnum` ASC"; } else { $query = "select * from `Table2_CordFT` where " . presentedCode($SeeAlso,$searchtype) . " AND `Source` IN ($NV, $TR, $BT) ORDER BY `Lnum` ASC"; }
  5. Thank you to both of you. I have been trying to find an answer for this issue for too long. Had a previous thread but no replies. I am below novice level so the help is really, really appreciated. Thank you again. Freaks rule!
  6. I want to replace/highlight more than one word in a string. How do I do it? The following code works great but it only highlights/replaces one word in the string. Thank you in advance for any replies. <? function highlight_search_criteria($search_results, $search_criteria, $bgcolor='Yellow') { //echo $search_criteria; if (empty($search_criteria)) { return $search_results; } else { $start_tag = "<span style='background-color: $bgcolor'>"; $end_tag = '</span>'; $highlighted_results = $start_tag . $search_criteria . $end_tag; return eregi_replace($search_criteria, $highlighted_results, $search_results); } } $term; $term[0] = 'John Doe'; $term[1] = 'Jane Smith'; $term[2] = 'Bill Bobbins'; foreach( $term as $value) { $bgcolor='Yellow'; $start_tag = "<span style='background-color: $bgcolor'>"; $end_tag = '</span>'; $db_result_text = "The users with the most points in this game were John Doe, Jane Smith, and Bill Bobbins."; $result_text = highlight_search_criteria($db_result_text, $value); } //result_text is the sentence or string with a highlighted word echo " result_text = ", $result_text; ?>
  7. Thank you, obsidian, for the inquiry. How I am trying to implement the code may be the problem. I am calling the function as seen below. I have numerous fields in my db. Two of those fields are $Topic and $Subtopic. $Topic = highlight_search_criteria($Topic, $SeeAlso); $Subtopic = highlight_search_criteria($Subtopic, $SeeAlso); Calling the following function with the above calls to $Topic and $Subtopic, does work without any problems. function highlight_search_criteria1($search_results, $search_criteria, $bgcolor='Yellow') { if (empty($search_criteria)) { return $search_results; } elseif { $start_tag = "<span style='background-color: $bgcolor'>"; $end_tag = '</span>'; $highlighted_results = $start_tag . $search_criteria . $end_tag; return eregi_replace($search_criteria, $highlighted_results, $search_results); } } else { } However, using these calls to the function when the function uses "for each" results in no highlighting. I do not have a clue as to what is going on. Any help would be sincerely appreciated. At a minimum, I would like to get the code with "for each" to work anywhere, just so I know the code is good and then I can try and determine where else the problem might be. OR Maybe I could find code elsewhere that is know to be bug free and then I could thest that bug-free code in my app. Thank you again for the response.
  8. Here is another script I could not get to work. function highlight_search_criteria($search_results, $search_criteria, $bgcolor = 'Yellow') { $start_tag = "<span style=\"background-color: $bgcolor;\">"; $end_tag = '</span>'; if (empty($search_criteria)) { return $search_results; } if (is_array($search_criteria)) { foreach ($search_criteria AS $keyword) { $search_results = str_replace($keyword, "$start_tag . $keyword . $end_tag", $search_results); } } else { $search_results = str_replace($search_criteria, "$start_tag . $search_criteria . $end_tag", $search_results); } return $search_results; }
  9. I am getting really frustrated trying to find a script to highlight multiple search terms using a boolean search feature on my site. For example, when you type in an AND or OR search request here in Freaks, the result set is highlighted for each of teh search terms you type in. For example, you can type in "highlight" AND "code" and the result set will show you words highlighted. The highlighted words will be "highlight" and "code" without the quotes. I have found very few scripts on the web that are workable. The scripts I have found I do not know how to adapt to my site. My site gets input from an html form. The search variable coming into the php script is $SeeAlso. So if the user wants to search for "dog" AND "muzzle", $SeeAlso will = "dog AND muzzle". I have an explode function that turns $SeeAlso into $terms[0], $terms[1], $terms[2], $terms[3], $terms[4], $terms[5], and $trimmed. $trimmed = all the search terms without any stop words. So a major question now would be is this... Is there any code anywhere that will do what the Freaks board does in highlighting search terms? Where is the code? Can you paste the code into a response to this question? Now, I found the code below but cannot get the code to highlight any terms in the php script I put the code into. I am a novice at php. No, I am below a novice. I do not care what script I use, just so I get one I can make work. Like I said above, I cannot get this code to work. It may be the way I am imputting the variables. If I can get a sample code to work, maybe I can fashion my own script if no scripts are available on the web. This search has been a multi-week effort so I am getting a little frustrated using forums doing what I want done, if you get my drift. Thank you in advance for any replies. <? //if you don't need to strip anything from the string //$terms = explode(" ", str_replace(array("+","-","*","~","\"","(",")","<",">","\"),"",$search))); // highlight search terms function function highlight($buffer) { global $terms; //create an array of colours for highlights $colors = array('80A000','922292','990000','707070','008080','999900','009999','1111FF','FF00FF','808080','008000','006666','800033','000080'); //set $i - this controls which colour is used $i=0; // do the replace for each word in the array foreach($terms as $needle){ //if you run out of colours, start over if ($i>count($colors)-1) { $i=0; } //surround matches with highlight span $buffer = eregi_replace($needle, "<span style='background-color:#$colors[$i]'></span>",$buffer); //increment $i so next colour is different $i++; } //send the results back to output return $buffer; } ?> <? $search = "cows pigs horshes sheep"; //convert search string to array minus operators $terms = explode(" ",$search); ob_start(highlight); echo $terms; echo $terms[0]; echo $terms[1]; echo $terms[2]; ob_end_flush() ?>
  10. I have solved or resolved this issue. With the following function. To run the function, you need to create a stopword file name stopwords.php. A sample of the file contents is below. In my example, if the user inputs any of the words or all of the words dog, red, or max, those words will be stripped from the user input and replaced by a blank space. function stopwordfilter($userinput){ //This function filters stopwords from the users input. $FileName="stopwords.php"; $list = file ($FileName); foreach ($list as $value) { list ($stopword,$filter,) = explode ("|^|", $value); $userinput = eregi_replace($stopword, $filter, $userinput); } return $userinput; } //see if the stopwords filter works $userinput = stopwordfilter($userinput); //these lines go in a file called stopwords.php //if the user types in or inputs any of these words, these words will be replaced by a blank space. dog|^| |^| red|^| |^| max|^| |^| Thank you for the followup posts.
  11. I have solved or resolved this issue. With the following function. To run the function, you need to create a stopword file name stopwords.php. A sample of the file contents is below. In my example, if the user inputs any of the words or all of the words dog, red, or max, those words will be stripped from the user input and replaced by a blank space. function stopwordfilter($userinput){ //This function filters stopwords from the users input. $FileName="stopwords.php"; $list = file ($FileName); foreach ($list as $value) { list ($stopword,$filter,) = explode ("|^|", $value); $userinput = eregi_replace($stopword, $filter, $userinput); } return $userinput; } //see if the stopwords filter works $userinput = stopwordfilter($userinput); //these lines go in a file called stopwords.php //if the user types in or inputs any of these words, these words will be replaced by a blank space. dog|^| |^| red|^| |^| max|^| |^|
  12. Thank you Wildbug. Yes, I want to do what you have described. I want to do what MySql inherently does in that MySql does indeed remove the stop words and any words outside of range. However, just removing the stopwords, ect. is not my ultimate objective. My ultimate objective is to highlight the search terms not removed. I want to highlight the words MySql uses to find text. I need to put those parsed words into an array or a function after the parsing takes place. Now, here is the initial question rephrased, HOW do I do what you describe. Thank you again for your reply.
  13. I want to gain access to the function or process MySql uses to parse words and phrases for Full Text searching. Here is an example. If the user inputs... Milan in history MySql will search for milan, history, and milan history. Is there a way to extract just the combination of terms MySql uses to search the db without the stop words? Stop words are automatically eliminated from the search request unless the user encloses a phrase in quotes. What I am trying to do is develop a script to highlight found search terms and phrases. I can explode a phrase into single words but if I do that the stop words would be included in the array. If there is some way of getting into the parsed words or phrases MySql Full Text actually uses to search, I can use each of those combinations as a keyword in my highlighting script. This request is about searching for the code or any code related to the questions involved. Thank you in advance for any replies.
  14. Thank you Corbin for the response. In regard to your comment, can you give me some examples as to how to explode the sql results and buffer the content? I know the theory you present. What I need is the code or code examples. Thank you again.
  15. I have a boolean search feature for my site. On the standard non-boolean search features I have highlighting of the found terms. I want to be able to highlight found terms of a boolean search. Is there a way to highlight found search terms for a boolean result set? OR Is there a way to explode the result string of the Select statement and pick out the words used by the embedded MySql boolean search engine? Here is the query statement... $query2 = " SELECT *, MATCH(Topic, Subtopic) AGAINST ('$all $none $any' IN BOOLEAN MODE) FROM View2_ConcordFT WHERE MATCH(Topic, Subtopic) AGAINST ('$all $none $any' IN BOOLEAN MODE) LIMIT $startrecord, $display"; Here is the result statement... $result2 = mysql_query($query2) or die("The query $query2 failed. MySQL said: " . mysql_error()); Thank you in advance for any replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.