session_start();
$_SESSION['word'] = $_POST['searchbar'];
$search = $_SESSION['word'];
if ($search == "") { //stopping any blank fields
echo "<p align=center><b>Please Enter Something To Search For In The Search Box.</b></p>";
}
else
{
$result = mysql_query("SELECT * FROM clothes WHERE (`title` LIKE '%".$search."%') || (`description` LIKE '%".$search."%')") or die(mysql_error()); //trying to do a statement that asks for a search to be done on TITLE and DESCRIPTION for what ever term someone has searched for so I can show them the results
echo "<p align=center>You Searched For $search</p>"; //showing the term that is being searched
if($result[0] == 0) //checking to see if the results come up as NONE then the following message to be shown
{
echo "<p align=center><b><font size=3>No Results Were Found.</font></b></p>";
}
else
{
//if there are some results from the term then the following tables are shown
echo "results shown here";
}
}
my issue I am having is I am not receiving any results with my OR statement.
The search term shows, the search works without the OR statement but as soon as I try to search the TITLE and DESCRIPTION columns for results it does not like it.
Any help?
session_start();
$_SESSION['word'] = $_POST['searchbar'];
$search = $_SESSION['word'];
if ($search == "") {
echo "<p align=center><b>Please Enter Something To Search For In The Search Box.</b></p>";
}
else
{
$searchTerms = explode(' ', $search);
$searchTermBits = array();
foreach ($searchTerms as $term) {
$term = trim($term);
if (!empty($term)) {
$searchTermBits[] = "description OR title LIKE '%$term%'";
}
}
$result = mysql_query("SELECT * FROM clothes WHERE ".implode(' OR ', $searchTermBits)."") or die(mysql_error());
echo "<p align=center>You Searched For $search</p>";
$journey = mysql_num_rows($result);
if ($journey == 0) {
echo "<p align=center><b>There Were No Results. Please Try Again</b></p>";
}
else
{
while($resultr=mysql_fetch_assoc($result))
echo "result here";
}
}
changed it quite a bit, it still reads off two areas but doesn't search for a precise term as it did before instead someone can search for "extra large mens tshirt" and mens tshirts will come up as long as that is stated in the TITLE or in the description "terms of Men or Tshirt or Large or Extra" etc.