$query = "select blah, blah blah where 1=1 ";
if ($institution){
$query .= " and institution like '%$institution%' ";
}
if ($name){
$query .= " and name like '%$name%' ";
}
.
.
.
--
Visit the Zend Store at http://www.zend.com/store/
Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm
----- Original Message -----
From: Bob Stone <[EMAIL PROTECTED]>
Newsgroups: php.general
Sent: Friday, March 30, 2001 5:52 PM
Subject: [PHP] How to eliminate bad fields from a mysql query?
> Dear PHP Helpers,
>
> Can you direct me to a solution for this problem:
>
> How can I eliminate bad (blank or incorrect) fields
> from a mysql query? In other words, if someone leaves
> a form field blank or enters a value that does not
> have a matching entry in the database, how can I
> eliminate that variable from the query?
>
> The query that I am using now works fine if the user
> enters a value in field that exists in the database.
> However if a field is left blank or incorrect data is
> entered, no results will display on the screen.
>
> Here is the code that I am using:
>
> $result = mysql_query("SELECT salutation, first_name,
> mid_name, user_name, cert_deg, job_title, institution,
> address_1, address_2, geo_loc, state, zip, country,
> phone, fax, e_mail FROM svt_members where first_name
> like '$first_name' && user_name like '$user_name' &&
> institution like '$institution' && state='$state' &&
> country like '$country'", $db);
>
> while ($myrow = mysql_fetch_array($result)) {
>
> printf("Name: <b><font color=\"green\" size=\"5s\">%s
> %s %s %s\n<br></b></font>", $myrow["salutation"],
> $myrow["first_name"], $myrow["mid_name"],
> $myrow["user_name"]);
>
> printf("Credentials and Degrees: <b><font
> color=\"blue\" size=\2\">%s</font></b><br>Job Title:
> <b><font color=\"blue\"
> size=\2\">%s</font></b><br>Company/Institution:
> <b><font color=\"blue\"
> size=\2\">%s<br></font></b>Address: <b><font
> color=\"blue\" size=\2\">%s %s<br></font></b>City:
> <b><font color=\"blue\" size=\2\">%s</font></b>
> State/Province: <b><font color=\"blue\"
> size=\2\">%s<br></font></b>Country: <b><font
> color=\"blue\" size=\2\">%s</font></b> Postal Code:
> <b><font color=\"blue\"
> size=\2\">%s<br></font></b>Voice: <b><font
> color=\"blue\" size=\2\">%s</font></b> Fax: <b><font
> color=\"blue\" size=\2\">%s<br></font></b>E-mail:
> <b><font color=\"blue\" size=\2\">%s\n<P></b></font>",
> $myrow["cert_deg"], $myrow["job_title"],
> $myrow["institution"], $myrow["address_1"],
> $myrow["address_2"], $myrow["geo_loc"],
> $myrow["state"], $myrow["country"], $myrow["zip"],
> $myrow["phone"], $myrow["fax"], $myrow["e_mail"]);
> }
>
> So if (for instance) a user enters data for each field
> except institution, how can I get the query to
> disregard $institution?
>
> Or if there is a better approach that I should be
> using instead of the above, please let me know.
>
> Thank you,
>
> Bob
>
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/?.refer=text
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]