RE: [PHP-DB] Help with search form using multiple fields

From: Date: Fri, 23 Jul 2004 21:53:22 +0000
Subject: RE: [PHP-DB] Help with search form using multiple fields
Groups: php.db 
Request: Send a blank email to php-db+get-35449@lists.php.net to get a copy of this message
$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: vjordan@smartparts.com [mailto:vjordan@smartparts.com] Sent: Friday, July 23, 2004 11:47 AM To: php-db@lists.php.net 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

« previous php.db (#35449) next »