[PHP-DB] Probably an easy question - blank search fields (PHP MySQL)

2002-01-06 Thread Gary Smith

Hiya, I'm writing a backend in MySQL with a PHP frontend. One of the PHP
pages searches the database. The user can enter as many or as few fields as
they like. I then search the database using this code:

$result = mysql_query(select * from equipment where (category='$category')
and (description like '$description') and (roomloc='$roomloc') and
(quantity like '$quantity') and (serialno like '$serialno') and (patdue
like '$patdue'),$db);

Messy, I know. The category and roomloc are options and therefore are
definite. However, if the user enters nothing for the other fields, they
get given no results. If I set the default value of each field to % in the
page that calls this, then it works fine. 

It's just not what I'd like to do - have the user clear out % from each
field before putting their data in. Is there an easy way to code if the
field is blank, send %, else send the users entry or just putting % before
whatever is sent? (this shouldn't mess up what's being entered, surely?)

Thanks for any help.
-- 
Gary Smith
E: [EMAIL PROTECTED]
W: http://www.l33t-d00d.co.uk
Pics: http://photos.l33t-d00d.co.uk

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




Re: [PHP-DB] Probably an easy question - blank search fields (PHP MySQL)

2002-01-06 Thread Bogdan Stancescu

$result = mysql_query(select * from equipment where (category='$category')
  and (description like '%$description') and (roomloc='$roomloc') and
  (quantity like '%$quantity') and (serialno like '%$serialno') and (patdue
  like '%$patdue'),$db);

Gary Smith wrote:

 Hiya, I'm writing a backend in MySQL with a PHP frontend. One of the PHP
 pages searches the database. The user can enter as many or as few fields as
 they like. I then search the database using this code:

 $result = mysql_query(select * from equipment where (category='$category')
 and (description like '$description') and (roomloc='$roomloc') and
 (quantity like '$quantity') and (serialno like '$serialno') and (patdue
 like '$patdue'),$db);

 Messy, I know. The category and roomloc are options and therefore are
 definite. However, if the user enters nothing for the other fields, they
 get given no results. If I set the default value of each field to % in the
 page that calls this, then it works fine.

 It's just not what I'd like to do - have the user clear out % from each
 field before putting their data in. Is there an easy way to code if the
 field is blank, send %, else send the users entry or just putting % before
 whatever is sent? (this shouldn't mess up what's being entered, surely?)

 Thanks for any help.
 --
 Gary Smith
 E: [EMAIL PROTECTED]
 W: http://www.l33t-d00d.co.uk
 Pics: http://photos.l33t-d00d.co.uk

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