Page 1 of 1

The first record is left behind

Posted: Wed Jun 04, 2003 2:18 pm
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

Posted: Wed Jun 04, 2003 2:23 pm
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..