AW: AW: AW: AW: [PHP-DB] php and OCI

From: Date: Wed, 14 Feb 2001 15:10:42 +0000
Subject: AW: AW: AW: AW: [PHP-DB] php and OCI
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-6612@lists.php.net to get a copy of this message
MAYBE THERES ANOTHER WAY; but before selecting or fertching all you wont know Are you saying that, in php, every query has to be perfomed twice, if you want to know the number of rows in selection (before the fetch loop)? Matthias Kopolt wrote: > OK: > > imagine you want to find all rows where COLOR = 'foo' : > > $st1 = ociparse ($conn, "SELECT count(*) FROM myTable WHERE COLOR = > 'foo'"); > ociexecute($st1,OCI_DEFAULT); > ocifetch ($st1); > $number_of_rows = ociresult ($st1, 1); //e.g. 372 > > $st2 = ociparse ($conn, "SELECT ID, NAME FROM myTable WHERE COLOR = > 'foo'"); > ociexecute($st2,OCI_DEFAULT); > while (ocifetch($st2)) { > echo "<hr> ID : ".ociresult ($st2, 1); > echo "<br> NAME : ".ociresult ($st2, 2); > } //this will return about 372 datarows > > $st3 = ociparse ($conn, "SELECT ID, NAME FROM myTable WHERE COLOR = 'foo' > AND ROWNUM <= 10"); > ociexecute($st1,OCI_DEFAULT); > while (ocifetch($st3)) { > echo "<hr> ID : ".ociresult ($st3, 1); > echo "<br> NAME : ".ociresult ($st3, 2); > } //this will return max 10 datarows > > //remember to ocifreestatement($st..) every ressource when duing continuos > queries > > /* > rownum is a metacolumn that is a signed during retrieving data from > database, but before sorting it. > so " where rownum < 11 order by points desc " will not give you the top ten > but, the first 10 entries in the list, ortderd by points. > > to overcom that do subselects : > "select * from (select * from table where foocondition order by foo) where > rownum < 10 " > > mk -- ================================================================== Valerio Ferrucci Tabasoft Sas valfer@flashnet.it http://tabasoft.ancitel.it taba@flashnet.it

« previous php.db (#6612) next »