[thelist] SQL question
Tom Dell'Aringa
pixelmech at yahoo.com
Wed Jan 22 13:36:01 CST 2003
Hiyo,
I am writing a search SQL statement. I am searching for results based
on
manFirst
manLast
womFirst
womLast
and the user picks one before I search. However, it has been
requested that if the user doesn't pick a parameter that I search on
all the names.
I have a variable called $byname that picks which parameter they
chose (if they did). So I have this:
----------------------------------------------------------
$searchname = $_POST["searchname"];
$byname = $_POST["byname"];
// find any result based on search parameters
if(isset($byname))
{
$result = @mysql_query(
"SELECT $byname FROM reguser WHERE $byname LIKE '$searchname'");
}
// the part above works fine...
else
{
** here is where I need a query to search ALL 4 name fields **
}
-----------------------------------------------------------
I started writing it then got stuck..how do I search 4 fields for the
same name? Can I use an OR in my select? That didn't seem right. This
is how I started..
SELECT
manFirst OR manLast OR womFirst OR womLast ????
FROM
reguser
WHERE
manFirst etc etc LIKE '$searchname'
But then how would I specify a WHERE clause..I think I'm barking up
the wrong tree! Do I have to do 4 SQL statements?
Tom
=====
var me = tom.pixelmech.webDeveloper();
http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
More information about the thelist
mailing list