The first record is left behind

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jiehuang001
Forum Commoner
Posts: 39
Joined: Mon May 12, 2003 12:53 pm

The first record is left behind

Post by jiehuang001 »

I am using the following code to retrieve records from a table:
$conn = ......
$query="select * from the_table"
$stmt = ociparse($conn,$query);
OCIExecute($stmt);
if (!OCIFetch($stmt)) {
print "no record available";
}else {
print "Here are the records.<br>";
// OCIExecute($stmt);
while (OCIFetch($stmt)) {
.....
}
}

However, if there are 10 records in the table, only 9 will be displayed. This is because after " if (!OCIFetch($stmt)) " is evaluated, the pointer is pointing to the record after the first one.

One trick is to use "OCIExecute($stmt); " twice, as I commented out above. But I doubt this is the most effective way. In JSP, there is such function as resultSet.next(), resultSet.beforeFirst(). Is there any similar function in PHP with Oracle?

Please help.

Thanks.

Jie Huang
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

the "fetch" is the same as a "next", so your first record is pointed to in your if statement, your while loop then moves the pointer to the second record before outputing anything..
Post Reply