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
[EMAIL PROTECTED]                      http://tabasoft.ancitel.it
                                        [EMAIL PROTECTED]



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to