Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199807

Re: [PHP3] Looping oracle select. From: Colin Viebrock (cmv <email protected>)
Date: 07/31/98

Also sprach Paul Monaghan (at 08:29 PM 7/30/98 -0400) ...
>Hey. I am querying an Oracle database, the data returned will be similar
>to the following:
>
>NPA NXX Suffix Metric
>--------------------------------------
>416 207 2276 1000
>905 333 8976 5000
>519 456 9876 100000
>516 675 9877 20000
>
>
>First things first. What is the best way to handle queries that return
>more than one line?

Depends on what you want to do with the data.

You can loop through the result, one row at a time: (note: I use mysql, so
you'll need to change all the sample code is below to the right PHP functions)

<?
$q=mysql_db_query($DBASE,"SELECT * FROM tablename");
while($result=mysql_fetch_array($q1)):
        ... do stuff, using the values in $result["NPA"], $result["NXX"], etc.
endwhile:
?>

Or assign everything to a multi-dim array:
<?
$q=mysql_db_query($DBASE,"SELECT * FROM tablename");
$i=0;
while($result[$i]=mysql_fetch_array($q1)):
        $i++;
endwhile:
... do stuff, using the values in $result[0]["NPA"], $result[3]["NXX"], etc.
?>

>How can I tell which of the results is the lowest?

The best way to do this is to have Oracle sort the results before you get
them:

<?
$q=mysql_db_query($DBASE,"SELECT * FROM tablename order by NPA");
?>

or

<?
$q=mysql_db_query($DBASE,"SELECT * FROM tablename order by NPA desc");
?>

That should get you started!

.........................................................................
Colin Viebrock Creative Director - Private World Communciations
cmv <email protected> http://www.privateworld.com
ICQ: 11386088

                                      This message was encoded with ROT26

--
PHP 3 Mailing List   http://www.php.net/
To unsubscribe send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest list:  php3-digest-subscribe <email protected>
For help: php3-help <email protected>  Archive:  http://www.php.net/mailsearch.php3