Forum Moderators: coopster
i have tried using RLIKE [[:<:]] [[:>:]] i get great 1 word results but i get no results on 2 word searches.
<?php
// GET THE SEARCH VARIABLE FROM URL AND BREAK INTO MULTIPLE WORDS
$var = @$_GET['q'] ;
$SearchString = explode ( " ", $var) ;
// NUMBER OF ROWS TO RETURN
$limit=30;
// CHECK FOR EMPTY STRING AND DISPLAY A MESSAGE
if (count($SearchString) == 0)
{
echo "<p>Please enter a search</p>";
exit;
} // PUT THE SEARCH TERMS BACK TOGETHER AS SEPARATE WORDS
$searchQuery = "" ;
for ($i = 0 ; $i < sizeof($SearchString) ; $i++)
{
$searchQuery .= "\"$SearchString[$i]\" ";
}
echo $searchQuery ;
// CHECK FOR A SEARCH PARAMETER
if (!isset($var))
{
echo "<p align=center>We dont seem to have a search parameter!</p>";
exit;
}
// CONNECT TO DATABASE
mysql_connect("localhost","#*$!#*$!xxx","xxxxxxxxx"); //(host, username, password)
// SPECIFY DATABASE
mysql_select_db("xxxxxxx") or die("Unable to select database"); //select which database we're using
// BUILD SQL QUERY, AND SPECIFY TABLE AND FIELD NAMES
$query = "SELECT * FROM products WHERE title LIKE $searchQuery ORDER BY price";
echo $query ;
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
$var2 = eregi_replace(" ", "+", $var);
// 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");
<?php
// display what the person searched for
echo "<p align=left><h1>$var</h1></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["title"];
$price = $row["price"];
*******Echo results here********
$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=\"$prevs/$var2.html\"><<
Prev 30</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=\"$news/$var2.html\">Next 30 >></a>";
}
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
//echo "<p>$numrows</p>";
?>
Can anyone please point out any errors or suggestions, TIA
Can anyone help please
<?php
// GET THE SEARCH VARIABLE FROM URL AND BREAK INTO MULTIPLE WORDS
$var = @$_GET['q'] ;
$array = explode(" ", trim($var));
// NUMBER OF ROWS TO RETURN
$limit=30;$n=(count($array));
$o=($n-1);
//echo $n;
//echo $o;
for ($i = 0 ; $i < $o ; $i++);
{
$searchQuery .= "\"%$array[$i]%\" or title like";
}
for ($k = $o ; $k < $n ; $k++);
{
$searchQuery2 .= "\"%$array[$i]%\"";
}
//echo $searchQuery;
//echo $searchQuery2;
// CONNECT TO DATABASE
mysql_connect("localhost","#*$!xx","#*$!xxxx"); //(host, username, password)
// SPECIFY DATABASE
mysql_select_db("xxxxxx") or die("Unable to select database"); //select which database we're using
// BUILD SQL QUERY, AND SPECIFY TABLE AND FIELD NAMES
$query = "SELECT * FROM products WHERE title like $searchQuery $searchQuery2 ORDER BY price";