I used the following code trying to display the total number of records and then dispaly all records. However, I can only be able to get the count number after the loop. How can I print the count number before printing the actual records?
-------------------the code--------------------------
$conn = // details omitted
$query = "select username, password from usertable";
$stmt = ociparse($conn,$query);
OCIDefineByName($stmt,"USERNAME",$username);
OCIDefineByName($stmt,"PASSWORD",$password);
OCIExecute($stmt);
while (OCIFetch($stmt)) {
print $username. " ". $password."/n";
}
$total_record = OCIRowCount($stmt);
print $total_record. " total records available".
Get the record count before getting the records?
Moderator: General Moderators
-
jiehuang001
- Forum Commoner
- Posts: 39
- Joined: Mon May 12, 2003 12:53 pm
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Are you saying that:
allows you to get the row count but
doesn't?
Mac
Code: Select all
while (OCIFetch($stmt)) {
print $username. " ". $password."/n";
}
$total_record = OCIRowCount($stmt);
print $total_record. " total records available".Code: Select all
$total_record = OCIRowCount($stmt);
print $total_record. " total records available".
while (OCIFetch($stmt)) {
print $username. " ". $password."/n";
}Mac
-
jiehuang001
- Forum Commoner
- Posts: 39
- Joined: Mon May 12, 2003 12:53 pm
Get count number before getting records
That is correct. You can try it yourself. The issue is that if you put
OCIRowCount() before the loop, it always returns 0.
OCIRowCount() before the loop, it always returns 0.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Best place to start with problems is the manual:
http://php.net/ocirowcount
http://php.net/ocirowcount
MacPHP manual - OCIRowCount() wrote:ocirowcount() returns the number of rows affected for eg update-statements. This function will not tell you the number of rows that a select will return!