[PHP] Help with Numbers
I am looking for a way to find the highest 5 and lowest 5 numbers within 300 or so numbers. Here is what I have so far... $Tickers = array(); $Current = array(); // SQL QUERY TO GET TICKERS MSSQL_CONNECT($HostName,$UserName,$Password); mssql_select_db($DBName) or DIE(Table unavailable); $Results = MSSQL_QUERY(SELECT CompanyName,Ticker FROM Company WHERE Ticker != ''); $RowCount = MSSQL_NUM_ROWS($Results); print $RowCount Number of Tickersbr\n; if($RowCount != 0) { for ($i = 0; $Field = MSSQL_FETCH_ARRAY($Results); ++$i) { array_push($Tickers, $Field[Ticker]); } } else { print There was nothing selected in the Query, it may have been bad.; } foreach($Tickers as $Ticker) { Get Last price on the ticker from database. and... array_push($Current, $Value); } Now that I have the values in an array I would like to pull out the five highest and the 5 lowest. Is there a way to do thatif not, is there another way to do what I am looking for. I keep thinking I would have to compare each ticker against all the others to verify it's standing...and that seems like a lot of work. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with Numbers
Sort the arrays and pick off the first and last elements. On Wed, 2 Oct 2002, Christopher J. Crane wrote: I am looking for a way to find the highest 5 and lowest 5 numbers within 300 or so numbers. Here is what I have so far... $Tickers = array(); $Current = array(); // SQL QUERY TO GET TICKERS MSSQL_CONNECT($HostName,$UserName,$Password); mssql_select_db($DBName) or DIE(Table unavailable); $Results = MSSQL_QUERY(SELECT CompanyName,Ticker FROM Company WHERE Ticker != ''); $RowCount = MSSQL_NUM_ROWS($Results); print $RowCount Number of Tickersbr\n; if($RowCount != 0) { for ($i = 0; $Field = MSSQL_FETCH_ARRAY($Results); ++$i) { array_push($Tickers, $Field[Ticker]); } } else { print There was nothing selected in the Query, it may have been bad.; } foreach($Tickers as $Ticker) { Get Last price on the ticker from database. and... array_push($Current, $Value); } Now that I have the values in an array I would like to pull out the five highest and the 5 lowest. Is there a way to do thatif not, is there another way to do what I am looking for. I keep thinking I would have to compare each ticker against all the others to verify it's standing...and that seems like a lot of work. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with Numbers
Thank you very much, I did not know sort would work this way. Makes complete sense now though. Thansk again I will give it a shot. Rasmus Lerdorf [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Sort the arrays and pick off the first and last elements. On Wed, 2 Oct 2002, Christopher J. Crane wrote: I am looking for a way to find the highest 5 and lowest 5 numbers within 300 or so numbers. Here is what I have so far... $Tickers = array(); $Current = array(); // SQL QUERY TO GET TICKERS MSSQL_CONNECT($HostName,$UserName,$Password); mssql_select_db($DBName) or DIE(Table unavailable); $Results = MSSQL_QUERY(SELECT CompanyName,Ticker FROM Company WHERE Ticker != ''); $RowCount = MSSQL_NUM_ROWS($Results); print $RowCount Number of Tickersbr\n; if($RowCount != 0) { for ($i = 0; $Field = MSSQL_FETCH_ARRAY($Results); ++$i) { array_push($Tickers, $Field[Ticker]); } } else { print There was nothing selected in the Query, it may have been bad.; } foreach($Tickers as $Ticker) { Get Last price on the ticker from database. and... array_push($Current, $Value); } Now that I have the values in an array I would like to pull out the five highest and the 5 lowest. Is there a way to do thatif not, is there another way to do what I am looking for. I keep thinking I would have to compare each ticker against all the others to verify it's standing...and that seems like a lot of work. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php