Hi folks,
As a former ColdFusion "programmer" I was used to fetch some rows from a query like:
<cfquery name="ab" datasource="my_ab">
select name,phone from adressbook
order by name
</cfquery>
Suppose it returns 100 rows, but I want to show it 10 by 10. With ColdFusion I could declare an "startrow" and "endrow" clauses in <cfloop> and fetch only the desired rows:
<cfloop query="ab" startrow="10" endrow="20">
....
</cfloop>
It seems to me that the ColdFusion Application Server gets the whole query and then, when accessing it with the <cfloop> it shows only the desired rows. It also seems a better approach than a cursor-based access, like I've been doing with PHP.
Is there any way to do it with PHP, better than walking to the desired position and fetching the rows I need? (like the code below, which gets the 10h to 20th rows from a 100 rows query):
$result = # link identifier to the query above
$row = # temporary variable to hold the row result while I'm deciding to use or discard it
$result_array = array();
$i = 1;
while($i <= 20) {
$row = mssql_fetch_array($result);
if ($i >= 10) {
$result_array = array_push($row);
}
$i++;
}
mssql_free_result($result);
A suggestion could be use an altered syntax of msssql_fetch_array($result,10), indicating the starting position. Then would be no problem in counting the next 10 lines.
Thanks for any help,
Ricardo
As a former ColdFusion "programmer" I was used to fetch some rows from a query like:
<cfquery name="ab" datasource="my_ab">
select name,phone from adressbook
order by name
</cfquery>
Suppose it returns 100 rows, but I want to show it 10 by 10. With ColdFusion I could declare an "startrow" and "endrow" clauses in <cfloop> and fetch only the desired rows:
<cfloop query="ab" startrow="10" endrow="20">
....
</cfloop>
It seems to me that the ColdFusion Application Server gets the whole query and then, when accessing it with the <cfloop> it shows only the desired rows. It also seems a better approach than a cursor-based access, like I've been doing with PHP.
Is there any way to do it with PHP, better than walking to the desired position and fetching the rows I need? (like the code below, which gets the 10h to 20th rows from a 100 rows query):
$result = # link identifier to the query above
$row = # temporary variable to hold the row result while I'm deciding to use or discard it
$result_array = array();
$i = 1;
while($i <= 20) {
$row = mssql_fetch_array($result);
if ($i >= 10) {
$result_array = array_push($row);
}
$i++;
}
mssql_free_result($result);
A suggestion could be use an altered syntax of msssql_fetch_array($result,10), indicating the starting position. Then would be no problem in counting the next 10 lines.
Thanks for any help,
Ricardo