I have a PHP script that display all data dynamically from an Oracle table with pagination. But I'm getting an error: Warning: oci_fetch_array() [function.oci-fetch-array]: ORA-01002: fetch out of sequence.
How to fix this?
Here's my PHP script
$sqlQuery = "SELECT * FROM table";
$objParse = oci_parse($conn, $sqlQuery);
oci_execute ($objParse,OCI_DEFAULT);
//Pagination
$Per_Page = 5;
$Num_Rows = oci_fetch_all($objParse, $Result);
$Page = $_GET["Page"];
if(!isset($_GET["Page"])){
$Page=1;
} else {
$Page=$_GET["Page"];
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page){
$Num_Pages =1;
} else if(($Num_Rows % $Per_Page)==0){
$Num_Pages =($Num_Rows/$Per_Page) ;
} else {
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$Page_End = $Per_Page * $Page;
if ($Page_End > $Num_Rows){
$Page_End = $Num_Rows;
}
//Fetch the column name
echo "<div class=\"datatable\">";
echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n";
$ncols = oci_num_fields($objParse);
echo "<thead>";
echo "<tr class=\"title\">\n";
for ($i = 1; $i <= $ncols; ++$i){
$colname = oci_field_name($objParse, $i);
echo " <th><b>".htmlentities($colname, ENT_QUOTES)."</b></th>\n";
}
echo "<th><b>Action</b></th>";
echo "</tr>\n";
echo "</thead>";
for($i=$Page_Start;$i<$Page_End;$i++){
while (($row = oci_fetch_array($objParse, OCI_ASSOC+OCI_RETURN_NULLS)) != false){
echo "<tbody>\n";
echo "<tr>\n";
foreach ($row as $item){
echo "<td>".($item !== null ? htmlentities($item, ENT_QUOTES):" ")."</td>\n";
}
echo "<td><a href='pagination_oracle2.php?EmpID=".$row['EMPLOYEE_ID'][$i]."'>Edit</a></td>";
echo "</tr>\n";
echo "</tbody>\n";
}
}
echo "</table>\n";
?>
<div class="pagination">
Total: <?= $Num_Rows;?> | Record: <?php echo $Num_Pages;?> |
<br>Page:
<?
if($Prev_Page){
echo "<a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page){
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
} else {
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages){
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next >></a> ";
echo "</div>";
}
oci_close($conn);