[PHP-DB] How to eliminate bad fields from a mysql query?

2001-03-30 Thread Bob Stone

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: bfont color=\"green\" size=\"5s\"%s
%s %s %s\nbr/b/font", $myrow["salutation"],
$myrow["first_name"], $myrow["mid_name"],
$myrow["user_name"]);

printf("Credentials and Degrees: bfont
color=\"blue\" size=\2\"%s/font/bbrJob Title:
bfont color=\"blue\"
size=\2\"%s/font/bbrCompany/Institution:
bfont color=\"blue\"
size=\2\"%sbr/font/bAddress: bfont
color=\"blue\" size=\2\"%s %sbr/font/bCity:
bfont color=\"blue\" size=\2\"%s/font/b  
State/Province: bfont color=\"blue\"
size=\2\"%sbr/font/bCountry: bfont
color=\"blue\" size=\2\"%s/font/b   Postal Code:
bfont color=\"blue\"
size=\2\"%sbr/font/bVoice: bfont
color=\"blue\" size=\2\"%s/font/b   Fax: bfont
color=\"blue\" size=\2\"%sbr/font/bE-mail:
bfont color=\"blue\" size=\2\"%s\nP/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 Database 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-DB] How to print last row in an array using WHILE?

2001-03-26 Thread Bob Stone

Dear PHP Helpers,

I have an array created by an mysql select statement.

I have the code to display the "rows" from the select
statement.

Everything works fine except that only n-1 rows from
the array will display.

For example if the array contains four rows only three
will display. If the array contains one row, nothing
displays on the screen.

I understand that a WHILE loop will count down to zero
and then since it becomes false will quit, but how do
I get the last (or first) row to print?

Here is the code:

HTML

HEAD

TITLE/TITLE

/HEAD

BODY BGCOLOR="#FF" TEXT="#00" LINK="#FF"
VLINK="#800080"

?php

$db = mysql_connect("localhost" , "phpuser" ,
"phpuser");

mysql_select_db("SVT",$db);

// display individual record

if ($user_name) {

$result = mysql_query("SELECT * FROM svt_members
WHERE user_name='$user_name'",$db);

$myrow = mysql_fetch_array($result);

  while ($myrow = mysql_fetch_array($result)) {

printf("Full Name: bfont color=\"green\"
size=\"5\"%s %s %s %s\nbr/b/font",
$myrow["salutation"], $myrow["first_name"],
$myrow["mid_name"], $myrow["user_name"]);

printf("Credentials and Degrees: bfont
color=\"blue\" size=\3\"%s/font/b   Job Title:
bfont color=\"blue\"
size=\3\"%s/font/bbrCompany/Institution:
bfont color=\"blue\"
size=\3\"%sbr/font/bAddress: bfont
color=\"blue\" size=\3\"%s %sbr/font/bCity:
bfont color=\"blue\" size=\3\"%s/font/b  
State/Provence: bfont color=\"blue\"
size=\3\"%sbr/font/bCountry: bfont
color=\"blue\" size=\3\"%s/font/b   Postal Code:
bfont color=\"blue\"
size=\3\"%sbr/font/bVoice: bfont
color=\"blue\" size=\3\"%s/font/b   Fax: bfont
color=\"blue\" size=\3\"%sbr/font/bE-mail:
bfont color=\"blue\" size=\3\"%s\nP/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"]);

} 

}
?

form method="post" action="?php echo $PHP_SELF ?"

Enter Last Name To Search:  input type="Text"
name="user_name"p

input type="Submit" name="submit" value="Click To
Search"

/form

/BODY

/HTML

Thank you very much for your help.

Best regards,

Bob Stone

__
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/?.refer=text

-- 
PHP Database 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]