Re: difficult sql statement. Help needed

From: Date: Wed, 10 Apr 2002 15:00:07 +0000
Subject: Re: difficult sql statement. Help needed
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-18394@lists.php.net to get a copy of this message
The above post may be unclear.. What he did was used if() statements to compare whatever and generate the query differently based on what he found.. $lotsOdata = $database->result( "SELECT * FROM someTable" ); $count = mysql_num_rows( $lotsOdata ); while( $count > 0 ) { if( $lotsOdata[city] != "philly" ) { $sql = $database->query( "INSERT INTO otherTable $thisData" ); } else if( $this[thing] = $that ) { $sql = $database->query( "UPDATE someVar SET thisValue = $thatData" ); } } I hope this makes sense, and it's all correctly written.. I'm pretty new at this myself so I may have some bugs.. Later, Bob Weaver <phplists@woodenpickle.com> wrote in message news:20020410144831.66438.qmail@pb1.pair.com... > I don't know that I could help much with your statement.. But you mentioned > doing if() statements in SQL queries.. Well, my programmer always writes > them into PHP scripts then just runs them from there.. Then he can include > if() conditions, or whatever else he needs.. Just a quick little > cust_import_utility.php script.. > > --For what it's worth.. > > Bob > > "Andy" <news.letters@gmx.de> wrote in message > news:20020410132621.79283.qmail@pb1.pair.com... > > Hi there, > > > > I do have a sql statement where I could need some help on. > > > > There are 3 tables: provinces, cities, countries > > The result should be city, province, country but only if province is > > available. If not just display city and country.! > > > > Lets say we are searching for madrid. > > > > I did build following statement: > > SELECT c.city, c.ID, p.province, co.country FROM cities c, provinces > p, > > countries co WHERE c.city like 'madrid%' AND p.province_id = c.province_id > > AND p.country_code = c.country_code AND c.country_code = co.country_code > > ORDER BY country , province limit 0, 10 > > > > > > Works fine as long as there is a province for this city. But > unfortunatelly > > my db does not have for all countries provinces. But there is a madrid in > > spain. > > so I would like to change this querry to return madrid in spain even if > the > > province is unknown, but also if the province exists (in this case with > the > > name of the province) > > > > Maybe there is a way to do if statements in sql?? > > > > Thanx for any help > > > > Andy > > > > > > > >

« previous php.db (#18394) next »