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.'")';

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')";
}

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 :]

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.