Jump to content

query in multiple fields


luiskid

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)
{
Link to comment
https://forums.phpfreaks.com/topic/13716-query-in-multiple-fields/
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]

Archived

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

×
×
  • Create New...

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.