HowdeeDoodee Posted June 12, 2007 Share Posted June 12, 2007 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; Quote Link to comment https://forums.phpfreaks.com/topic/55256-values-without-single-quotes-not-being-picked-up-or-passed-with-eregi_replace/ Share on other sites More sharing options...
sasa Posted June 12, 2007 Share Posted June 12, 2007 No. Error is in part where you pool data from database. Can we see it? Quote Link to comment https://forums.phpfreaks.com/topic/55256-values-without-single-quotes-not-being-picked-up-or-passed-with-eregi_replace/#findComment-273192 Share on other sites More sharing options...
per1os Posted June 12, 2007 Share Posted June 12, 2007 Your not posting enough code, show us where $Topic is being assigned. Essentially what is happening is $Topic is a MySQL resource where as you think it is data retrieved. The Resource id #2, means it references a query that was ran, and if you throw that resource into mysql_fetch_array you will be able to pull out data from the data base that was assigned to that resource id. Either way $term is not assigned anything once you comment it out. You do not anyway shape or form try to convert $Topic into an array to use. Too many mistakes for this to even want to think about working without the $term array. Quote Link to comment https://forums.phpfreaks.com/topic/55256-values-without-single-quotes-not-being-picked-up-or-passed-with-eregi_replace/#findComment-273199 Share on other sites More sharing options...
HowdeeDoodee Posted June 12, 2007 Author Share Posted June 12, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/55256-values-without-single-quotes-not-being-picked-up-or-passed-with-eregi_replace/#findComment-273277 Share on other sites More sharing options...
HowdeeDoodee Posted June 12, 2007 Author Share Posted June 12, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/55256-values-without-single-quotes-not-being-picked-up-or-passed-with-eregi_replace/#findComment-273309 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.