Re: Probably an easy question - blank search fields (PHP & MySQL)

From: Date: Sun, 06 Jan 2002 14:22:01 +0000
Subject: Re: Probably an easy question - blank search fields (PHP & MySQL)
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-15450@lists.php.net to get a copy of this message
if (empty($var)) { } else { } -- Best regards, George Nicolae IT Manager ___________________ X-Playin - Professional Web Design www.x-playin.f2s.com "Gary Smith" <shadyron@l33t-d00d.co.uk> wrote in message news:3.0.6.32.20020106111855.00eb2940@195.11.11.77... > 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 <option>s 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: shadyron@l33t-d00d.co.uk > W: http://www.l33t-d00d.co.uk > Pics: http://photos.l33t-d00d.co.uk

« previous php.db (#15450) next »