Jump to content


Photo

query in multiple fields


  • Please log in to reply
3 replies to this topic

#1 luiskid

luiskid
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 05 July 2006 - 09:02 AM

i have made a query that contains a search field and a combobox where you can select the row.
the query is working if you want to search in one row, but i want to search in multimple rows!
i want that if i select the case 0 to search in all the rows

switch($field)
{
  case "0": $WHERE="WHERE (what should i write in here?) "; break; //

  case "1": $WHERE="WHERE Name; break;
 
  case "2": $WHERE="WHERE OBS"; break;
 
  case "3": $WHERE="WHERE Dept"; break;

}

$query = "select * from DB1 ".$WHERE." LIKE '%$search%'";

$result = mysql_db_query("DB", $query);

if ($result)
{

#2 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 05 July 2006 - 09:07 AM

Could you explain what you mean a bit better?

#3 luiskid

luiskid
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 05 July 2006 - 09:14 AM

i have a table and it look like this Name | Dept | OBS .. and if i select the option numer "0" from the combobox i want to search by all the fields (Name, Dept, OBS) 

#4 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 05 July 2006 - 09:20 AM

This should work:

<?php

switch( $field )
{
	case "0":
		$WHERE = "WHERE Name LIKE '%$search%' and OBS LIKE '%$search%' and Dept LIKE '%$search%'";
		break;
	case "1":
		$WHERE = "WHERE Name LIKE '%$search%'"; 
		break;
	case "2":
		$WHERE = "WHERE OBS LIKE '%$search%'";
		break;
	case "3":
		$WHERE = "WHERE Dept LIKE '%$search%'";
		break;
}

$query = "select * from DB1 " . $WHERE;
$result = mysql_db_query( "DB", $query );

?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users