Searching via a number of alternative fields
Posted by: Rick.Haden (---.range86-158.btcentralplus.com)
Date: February 14, 2009 11:02AM

Hi

I want to build a search page allowing the user to add info to one of a number of fields and use this as the search criteria. At first I thought that this would be a 'WHERE field1=?? OR field2=??, but this uses NULL for those fields not used. Is there a way other than using an if statement such as if field1!="" use this info else if field2 etc?

You can tell I am a newbie to all this,, eh?

Rick

Options: ReplyQuote
Re: Searching via a number of alternative fields
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 14, 2009 06:00PM

ul be using Match Against

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Searching via a number of alternative fields
Posted by: Rick.Haden (---.range86-158.btcentralplus.com)
Date: February 14, 2009 06:05PM

I saw that, but surely that searches a number of columns for the same data...mine is almost opposite..

I need

search lastname if someone has entered a name or search postcode if the postcode field was used etc etc

Rick

Options: ReplyQuote
Re: Searching via a number of alternative fields
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 14, 2009 06:40PM

do u have two inputs in the form? one for each? if so its very easy....

just check to see which is set in php and then search that column?

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Searching via a number of alternative fields
Posted by: Rick.Haden (---.range86-158.btcentralplus.com)
Date: February 14, 2009 06:52PM

Thank you Steven

Yes I do have a number of inputs. So, it is IF SET field1 etc?

Regards

Rick

Options: ReplyQuote
Re: Searching via a number of alternative fields
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 14, 2009 07:01PM

if (isset($_POST['$field1'])) {

$column_to_search= 'name';
}


if (isset($_POST['$field2'])) {

$column_to_search= 'postcode';
}



your probably best to make the form 1 input and 2 radio buttons (name and postcode)
so that they cant search both at same time which would cause issues with the above script

then ud use

if ($_POST['radiobutton']=='name')
{
$column_to_search= 'name';
$searchvalue=$_POST['inputbox'];
}

else

{
$column_to_search= 'postcode';
$searchvalue=$_POST['$inputbox'];
}

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]



Edited 1 time(s). Last edit at 02/15/2009 12:20PM by stevenmartin99.

Options: ReplyQuote
Re: Searching via a number of alternative fields
Posted by: Rick.Haden (---.range86-158.btcentralplus.com)
Date: February 15, 2009 11:20AM

Thank you

you don't know how much I appreciate your time..

Rick

Options: ReplyQuote
Re: Searching via a number of alternative fields
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 15, 2009 12:24PM

no problem.. you could also do it with two inputs and have them

if field1 is set and field2 is not set then search column 1
if field2 is set and field1 is not set then search column 2
if field1 and field2 is set then search column 1 and 2 using match against

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote


Sorry, only registered users may post in this forum.