$sql_start = "SELECT * FROM table_name WHERE ";
If($_POST['first_name'] != '') {
        $first_name = $_POST['first_name'];
        $sql_start .= "first_name LIKE '%$first_name%' AND ";
}
If($_POST['last_name'] != '') {
        $last_name = $_POST['last_name'];
        $sql_start .= "last_name LIKE '%$last_name%' AND ";
}
... ## for the rest of the fields

// Trim off the last AND
$sql = rtrim($sql_start," AND ");

And then do the $sql 



Gary Every
Sr. UNIX Administrator
Ingram Entertainment Inc.
2 Ingram Blvd, La Vergne, TN 37089
"Pay It Forward!"


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Friday, July 23, 2004 11:47 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Help with search form using multiple fields 



I have a search form on a page that i am having trouble with. i can not
seem to get the search string correct. In the form i have firstname,
lastname, homephone, and email. I would like to upon search return data
put in form. for example if i put "john" in firstname i want all rows
where firstname is john to return. or if "john" is entered in firstname
and "smith" is entered in lastname it will return all rows containing
john smith. I have a frame set to display the data on the same page as
the search page. I would also loke to data to print as a hyperlink
pointing to userdata.php?custid={the PK ID of custid }. also if no text
is entered and just search is pressed it will return all data in table
asc by lastname. 

could someone please help with this? 


Thanks

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to