Jump to content

Archived

This topic is now archived and is closed to further replies.

luiskid

query in multiple fields

Recommended Posts

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)
{

Share this post


Link to post
Share on other sites
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) 

Share this post


Link to post
Share on other sites
This should work:

[code]<?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 );

?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.