Re: Need Help on Sorting Arrays..

From: Date: Mon, 19 May 2003 10:33:18 +0000
Subject: Re: Need Help on Sorting Arrays..
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-27877@lists.php.net to get a copy of this message
hm...... Seems as if it was really impossible to make this with the query. (Unless one would change the dbmodel so that the connections get easier) Well to solve your array-problem use array_multisort: $supplier = array( 'FTSL1' , 'FTSL1' , 'FTSL2' , 'FTSL2' , 'FTSL2' , 'MIC' , 'MIC' , 'MIC' , 'MIC' , 'MIC' , 'MIC' ); $partCode = array( '954334-02310730' , '9445R0-05200730' , '324941-06100900' , '324941-06200900' , '324941-0570A900' , '981028-03570730' , '811600-41650730' , '811600-41050730' , '811600-31700740' , '954105-03050730' , '934100-03650730' ); $partName = array( 'Ceramic Condenser' , 'Ceramic Condenser' , 'Chemical Condenser' , 'Chemical Condenser' , 'Ceramic Condenser' , 'Connector' , 'IC' , 'IC' , 'IC' , 'Ceramic Condesner' , 'Capacitor' ); $partQty = array( 0 , 0 , 100 , 0 , 300 , 3000 , 2000 , 19000 , 2500 , 12000 , 2000 ); $soQty = array( 7890 , 10800 , 3300 , 4700 , 500 , 3000 , 654 , 18162 , 654 , 11166 , 546 ); $numbers = array( '2nd' , '1st' , '4th' , '5th' , '3rd' , '8th' , '11th' , '10th' , '9th' , '7th' , '6th' ); $ar = array( 'supplier' => $supplier , 'partName' => $partName , 'partCode' => $partCode , 'partQty' => $partQty , 'soQty' => $soQty , 'numbers' => $numbers ); // echo the 2d-array $cMax = count($ar['supplier']); for($c = 0; $c < $cMax; $c++) echo $ar['supplier'][$c].' | '. $ar['partName'][$c].' | '. $ar['partCode'][$c].' | '. $ar['partQty'][$c].' | '. $ar['soQty'][$c].' | '. $ar['numbers'][$c]. '<br>'."\n"; // sort it array_multisort($ar['supplier'], SORT_ASC, SORT_STRING , $ar['partName'], SORT_ASC, SORT_STRING , $ar['partCode'], SORT_ASC, SORT_STRING , $ar['partQty'] , $ar['soQty'] , $ar['numbers'] ); echo '<br><br>'; // echo the 2d-array $cMax = count($ar['supplier']); for($c = 0; $c < $cMax; $c++) echo $ar['supplier'][$c].' | '. $ar['partName'][$c].' | '. $ar['partCode'][$c].' | '. $ar['partQty'][$c].' | '. $ar['soQty'][$c].' | '. $ar['numbers'][$c]. '<br>'."\n"; hope this works, and helps?! .ma Gezeala 'Eyah' Bacuño II <gezeala@hotmail.com> wrote@19.05.2003 11:22 Uhr: > Hi! > > I'm not using MySql I'm using Postgresql.. > > Here is my query..Can't combine them...I have to compute for the sum of the > $poqty and $soqty.. > > // for so_qty > $sql="SELECT > CASE > WHEN MAX(a.part_alternate_id) isNull THEN > t.part_id > ELSE ( > SELECT part_alternate_child_id > FROM part_alternate q > WHERE q.part_alternate_id=( > SELECT MAX(b.part_alternate_id) > FROM part_alternate b > WHERE b.part_alternate_parent_id=t.part_id)) > END AS part_id, > SUM(t.quantity) AS sodqty, > t.part_id AS parent_id > FROM temp_so_parts_sum t > LEFT JOIN part_alternate a ON t.part_id=a.part_alternate_parent_id > LEFT JOIN part p ON t.part_id=p.part_id > WHERE userid=$users_id and part_model_id=$model_id > GROUP BY t.part_id"; > > $rs=$conn->execute($sql); > $result->set_resultset($rs); > while(!$result->EOF()) { > $temp=$result->get_row($rs); > $soqty[$temp["part_id"]]=$temp["sodqty"]; > $result->move_next(); > } > > $result=new pg_resultset; > > //for poqty > $sql="SELECT pod_part_supp_id,part_id ,(SUM(pod_qty) * part_divisor) AS > podqty > FROM vw_purchase_order_detail > WHERE po_lot_id IN ( > SELECT lot_id > FROM lot > WHERE lot_model_id=$model_id AND lot_id > BETWEEN $from_lot_id AND $to_lot_id > ) > AND po_model_id=$model_id > GROUP BY pod_part_supp_id,part_id,part_divisor "; > $rs=$conn->execute($sql); > $result->set_resultset($rs); > while(!$result->EOF()) { > $temp=$result->get_row($rs); > $poqty[$temp["part_id"]]=$temp["podqty"]; > $result->move_next(); > } > > // got all the part_id's from this table/view.. > $sql2="SELECT * FROM vw_part_supplier > LEFT JOIN model ON part_model_id=model_id > WHERE part_model_id=$model_id ORDER BY supplier_code, part_name, > part_longcode"; > $result=new pg_resultset; > $rs=$conn->execute($sql2); > $result->set_resultset($rs); > while(!$result->EOF()) { > $temp=$result->get_row($rs); > $supplier[$temp["part_id"]]=trim($temp["supplier_code"]); > $part_id[$temp["part_id"]]=$temp["part_id"]; > $name[$temp["part_id"]]=trim($temp["part_name"]); > $code[$temp["part_id"]]=trim($temp["part_longcode"]); > $short[$temp["part_id"]]=trim($temp["part_shortcode"]); > $model[$temp["part_id"]]=$temp["model_id"]; > $model_code[$temp["part_id"]]=trim($temp["model_code"]); > $model_desc[$temp["part_id"]]=trim($temp["model_desc"]); > $moq[$temp["part_id"]]=$temp["part_supp_min_qty"]; > $result->move_next(); > } > > TIA! > > Marie Gezeala M. Bacuño II > Information Systems Department > > Your choice: the red pill or the blue pill. > > _________________________________________________________________ > Help STOP SPAM with the new MSN 8 and get 2 months FREE* > http://join.msn.com/?page=features/junkmail >

« previous php.db (#27877) next »