Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO Recordset with X out of X records statement 1

Status
Not open for further replies.

MikeAuz1979

Programmer
Aug 28, 2006
80
AU
Hi,
Using PHP,Apache and MS-SQL2000 I'm trying to get the required sql output and a counter at the top that says something like '100 out of 15000 records returned' I have the below code thanks to and a bit of legwork but when I run this I get the result 100 out of 1 records returned. For some reason the variable $TC is only getting populated as 1 rather than the true count of the table.

NB: I'm working on the idea that I can re-use the ado connection hence the $rs->close();

Anyone have any ideas?
Thanks for any help
Mike

Code:
<?php

include('../adodb5/adodb.inc.php');
$db =& ADONewConnection('odbc_mssql');
$db->Connect('Driver={SQL Server};Server=localhost;Database=gb32_Tims', 'sa', 'potty');
//Get total no of rows in table
$sql = "Select Count(*) from account";
$rs = $db->execute($sql);
$TC = $rs->RecordCount();

$rs->close();
//Get limited results and row count of returned results
$sql = "Select acct_i from account";
$rs = $db->SelectLimit($sql,20,100); // Select x rows, starting at row y
print "[" . $rs->RecordCount() . " Out of "  . $TC . " Records Returned] <BR>"; // Display number of rows returned
while (!$rs->EOF) {
    print $rs->fields[0].'<BR>'; 
    $rs->MoveNext();  //  Moves to the next row
  }  // end while

php?>
 
it is only 1. you are retrieving a single row containing the total number of rows. that is what count(*) does.

so instead of addressing the recordcount property you need to address the field itself

Code:
$TC = $rs->fields[0];

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top