0

hello,
i have something like this
search:_______ search1:___________ submit btn

how can i search for something from the same table in the database considering both search fields?

I've tried this code nut it doesn't work.
thanks

if($search == '')
	{
		$smarty->assign('Error','Please enter any string!');
		$z=1;
	}
	elseif($type == 'like')
	{
		$sql = 'SELECT * FROM topic WHERE Title LIKE '."'$search%'".' AND Title1 LIKE '."'$search1%'";
	}
	elseif($type == 'exact')
	{
		$sql = 'SELECT * FROM topic WHERE MATCH (Title) AGAINST ("'.$search.'") AND (Title1) AGAINST ("'.$search1.'")';

Edited by patrioticcow: n/a

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by patrioticcow
0

You used double quotes, instead of single.

if($search == '')
{
  $smarty->assign('Error','Please enter any string!');
  $z=1;
}
elseif($type == 'like')
{
  $sql = "SELECT * FROM topic WHERE Title LIKE '$search%' AND Title1 LIKE '$search1%'";
}
elseif($type == 'exact')
{
  $sql = "SELECT * FROM topic WHERE MATCH (Title) AGAINST ('$search') AND (Title1) AGAINST ('$search1')";
}

Edited by pritaeas: n/a

0

What doesn't work exactly? You get a PHP or Sql error code or you get no results when you should be?

Edit: ok, you got a solution now :] Ignore this message :]

Edited by Daiva: n/a

0

What doesn't work exactly? You get a PHP or Sql error code or you get no results when you should be?

Edit: ok, you got a solution now :] Ignore this message :]

thanks for the reply

the single quotes improved the search, but.
it looks like the each search field finds results independent from each other. I want them to work together and the result to contain what is search in both fields

and i get no errors php or sql errors.

Edited by patrioticcow: n/a

0

hello.
i believe i fix it.
ill explin my results on the code

//this is the first search field
if($search == '')
	{
		$smarty->assign('Error','Please enter an departure location!');
		$z=1;
	}
//this is the second search field
	elseif($search1 == '')
	{
		$smarty->assign('Error','Please enter any destination!');
		$z=1;
	}
//both search fields are selecting and matching the search words from the table "topic" with the fields "Title1" and "Title2"
	elseif($type == 'like')
	{
		$sql = "SELECT * FROM topic WHERE Title LIKE '$search%' AND Title1 LIKE '$search1%'";
	}
	elseif($type == 'exact')
	{
		$sql = "SELECT * FROM topic WHERE MATCH (Title) AGAINST ('$search') AND (Title1) AGAINST ('$search1')";
		//$sql .= ' UNION ';
	}
//this is what solved my problem. i replace the $search with $search1.
	if($tag == 'tag' && $z!= 1)
	{
		$sql .= ' OR Tag LIKE "%'.$search1.'%"';
	}
//and off course the double quotes thing by pritaeas:)

ill keep u all posted if any problem occurs in the nearest future
thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.