Re: Genius help required with PHP MySQL problem

From: Date: Fri, 22 Dec 2000 23:58:47 +0000
Subject: Re: Genius help required with PHP MySQL problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-31638@lists.php.net to get a copy of this message
select * from cars where 1=1 and ....... HTH, Bojan Gajic Christian Dechery wrote: > At 16:22 22/12/00 +1300, you wrote: > >Hello Everybody, > > > >I am trying to return some results from MySql using PHP. > > > >What I have is this... > > > >SELECT * FROM cars WHERE make = > > > >It is after the equals that I want something that will select all of them. I > >know I could just have > >SELECT * FROM cars > >and leave it at that, but my problem occurs when I have another selection > > > >SELECT * FROM cars WHERE make = 'honda' AND trans = 'automatic' > > > >Becuase I am depending on what comes in from select boxes, if they don't > >select a make the code i have returns... > >SELECT * FROM car AND trans = 'automatic' > >This doesn't work for obvious reasons! > > I get that you don't want to use arrays... > I don't see use for an array here either... it's an if-else solution.... > > look: if you have two select boxes (make and trans)... u'll gotta have > something like this > <html>... > <select name="make"> > <option value="all">All</option> > ... > </select> > <select name="trans"> > <option value="all">All</option> > ... > </select>... > </html> > > now in PHP source... > <?php > $query = "select * from cars"; > if ($make!="all" || $trans!="all") > { > if ($make=="all") > $query.=" where trans='$trans'"; > else > $query.=" where make='$make'"; > } > echo $query; (or whatever) > ?> > of course if you have a lot more boxes this will be a very stupid solution > since you if clause would be huge, than u'd have to use an array to check > for "all's"... but for now this is a perfectly good solution.. don't u > think? > > ____________________________ > . Christian Dechery (lemming) > . http://www.tanamesa.com.br > . Gaita-L Owner / Web Developer > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#31638) next »