ahs10 Posted April 5, 2007 Share Posted April 5, 2007 first, my columns are set correctly, one is text, one is mediumtext. i've tweaked the code below to meet my needs, but the search is case sensitive. i would like a case insensitive search. can someone please tell me how to do this? <?php require_once("config.php"); $testquery = TRUE; $skip = FALSE; $lowlevel = $hlevel + 1; $var = @$_GET['q']; if (ereg("^\042?[A-z0-9+. -*<>()~]*[']?[A-z0-9+. -*<>()~]*\042?$",$var)) { $var1 = ereg_replace("\045","percent",$var); $trimmed = trim($var1); } else { $trimmed = "Invalid search term entered."; $testquery = FALSE; } $display = stripslashes($trimmed); 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"; } if ($skip != TRUE) { if (!defined('DB_USER')) { include("mysql_connect.php"); } if (($boolean == TRUE) && ($split == "OR")) { $query = "SELECT $db_fields FROM $db_table WHERE MATCH($db_fields) AGAINST ('$terms[0] $terms[1] $terms[2] $terms[3] $terms[4] $terms[5]' IN BOOLEAN MODE) ORDER BY $sort_order"; } elseif (($boolean == TRUE) && ($split == "AND")) { $query = "SELECT $db_fields FROM $db_table WHERE MATCH($db_fields) AGAINST ('+$terms[0] +$terms[1] +$terms[2] +$terms[3] +$terms[4] +$terms[5]' IN BOOLEAN MODE) ORDER BY $sort_order"; } else { $query = "SELECT $db_fields FROM $db_table WHERE MATCH($db_fields) AGAINST ('$trimmed' IN BOOLEAN MODE) ORDER BY $sort_order"; } $sub_query = "SELECT $db_id FROM $db_table WHERE $db_id LIKE \"in8valis1d\""; if ($testquery == FALSE) { $numresults = 0; $numrows = 0; } else { $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); } if ($numrows == 0) { echo "<h" . $hlevel . ">Your search returned no results.</h" . $hlevel . ">"; echo "<p>You searched for: "" . $display . ""</p>"; } if (empty($s)) { $s=0; } if ($testquery != FALSE) { $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); } else { $query .= " limit $s,$limit"; $result = mysql_query($sub_query) or die("Couldn't execute query"); } if ($numrows != 0) { echo "<h" . $hlevel . ">Results of your search:</h" . $hlevel . ">\n"; } echo "<p>You searched for: "<strong>" . $display . "</strong>"</p>\n\n"; echo "<h" . $lowlevel . ">Search Results</h" . $lowlevel . ">\n\n<dl id='searchresults'>\n"; $count = 1 + $s ; while ($row = mysql_fetch_array($result)) { $title = $row[$db_title]; $id = $row[$db_id]; if ($db_blurb == TRUE) { $blurb = substr($row[$db_content],0,$blurb_length) . ' . . .'; $blurb1 = strip_tags($blurb); } else { $blurb = ""; } $section = $row[$db_category]; echo "<dt>$count. <a href='IssueDetails.php?ID=$id'>$title $section</a></dt>\n"; if ($db_blurb == TRUE) { echo "<p>$blurb1</p>\n"; } $count++ ; } $currPage = (($s/$limit) + 1); echo "</dl>\n\n"; if ($s>=1) { $prevs=($s-$limit); print "<p class='jdprevious'><a href=\"$PHP_SELF?s=$prevs&q=$var\">← Previous Page</a></p>\n"; } $pages=intval($numrows/$limit); if ($numrows%$limit) { $pages++; } if ($numrows == 0) { echo ''; } elseif (!((($s+$limit)/$limit)==$pages) && $pages!=1) { $news=$s+$limit; echo "<p class='jdnext'><a href=\"$PHP_SELF?s=$news&q=$var\">Next Page →</a></p>\n"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; if ($numrows != 0) { echo "<p class='jdresults'>Results $b to $a of $numrows.</p>\n"; } else { echo "<p>Sorry, your search produced no results.</p>\n"; } } ?> Quote Link to comment Share on other sites More sharing options...
tippy_102 Posted April 7, 2007 Share Posted April 7, 2007 I believe IN BOOLEAN MODE makes it case sensitive. Quote Link to comment Share on other sites More sharing options...
ahs10 Posted April 9, 2007 Author Share Posted April 9, 2007 hello, thanks for taking the time to help me out. so i've tried taking out the IN BOOLEAN MODE and i get an error. the error results in a couple of lines below in..... error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in line of code error occurs $numrows=mysql_num_rows($numresults); so, my question then becomes, i would i write the following line of code without the IN BOOLEAN MODE part? $query = "SELECT $db_fields FROM $db_table WHERE MATCH($db_fields) AGAINST ('$trimmed' IN BOOLEAN MODE) ORDER BY $sort_order"; Quote Link to comment Share on other sites More sharing options...
youneek Posted April 15, 2007 Share Posted April 15, 2007 is the reason you want case insensitive because the data in the database is in different cases, or is it because the search could be in a different case? If it is because the search is in a different case couldn't you just use something like $str = "Mary Had A Little Lamb and She LOVED It So"; $str = strtolower($str); echo $str; // Prints mary had a little lamb and she loved it so Quote Link to comment Share on other sites More sharing options...
youneek Posted April 15, 2007 Share Posted April 15, 2007 You could use WHERE MATCH (your, terms) against if those terms where declared in: ADD FULLTEXT .....(your, terms)... Quote Link to comment 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.