RE: [PHP] Building a query on multiple variables, how to test for which variable A SOLUTION

From: Date: Wed, 28 Aug 2002 19:55:05 +0000
Subject: RE: [PHP] Building a query on multiple variables, how to test for which variable A SOLUTION
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-114419@lists.php.net to get a copy of this message
Todd came in with a good suggestion which I had started towards, so this is what I have arrived at for the moment. I will be looking to make this more elegant soon, but since they are screaming for the report now this is what I did; <?php if($usoc1 <> "--- Select ---"){ $usoc[] = $usoc1; } if($usoc2 <> "--- Select ---"){ $usoc[] = $usoc2; } if($usoc3 <> "--- Select ---"){ $usoc[] = $usoc3; } if($usoc4 <> "--- Select ---"){ $usoc[] = $usoc4; } $usoc_count = count($usoc); // query details $qpon = "SELECT BillDate, StateInd, BAN, Type, PON, Phrase, PhraseLine1, USOC, Description, RateZone, Rate "; $qpon .= "FROM tblUSOCChargesDetail WHERE "; $first = 0; for($i = 0; $i < $usoc_count; $i++){ if($first == 0){ $qpon .= "USOC = '" . $usoc[$i] . "' "; $first = 1; } else { $qpon .= "AND USOC = '" . $usoc[$i] . "' "; } } $qpon .= "ORDER BY BillDate "; if(!($dbpon = mysql_query($qpon, $dbconnect))){ print("MySQL reports: " . mysql_error() . "\n"); exit(); } ?> I am sure that there is a more elegant solution, if I find it I will let you know. Thanks! Jay

« previous php.general (#114419) next »