Hi all,
I have a problem during displaying my query. My pagination works fine but the records display not sorted. I did insert the clause "order by name ASC" but still the same unless if I display all records in 1 page, it is sorted, but if multiple pages, records not sorted. Please help me. I've paste my codes below:
<?
// Connect To Oracle Server
$conn = OCILogon("username", "password", "database");
// set number of results to display per page
$pagelimit = "25";
// run query
$strSQL1 = OCIParse($conn,"select x.matric_no matric_no, y.name name, w.year year from uia.alumni_info x, uia.student_st y, uia.acad z, uia.graduate w where x.matric_no = y.matric_no and y.acad_prog1 = z.acad_code and z.kuliyyah = 'ENGIN' and x.matric_no = w.matric_no order by y.name ASC");
OCIExecute($strSQL1);
// count number of matches
$totalrows = OCIFetchStatement($strSQL1,$results);
// determine how many pages there will be by using ceil() and dividing total rows by pagelimit
$pagenums = ceil ($totalrows/$pagelimit);
// if no value for page, page = 1
if ($page==''){
$page='1';
}
// create a start value and limit value
$start = (($page-1) * $pagelimit)+1;
//$start = 1;
$limit = $start+($pagelimit-1);
// showing Results 1 to 1 (or if you're page limit were 5) 1 to 5, etc.
$starting_no = $start;
if ($totalrows - $start < $pagelimit) {
$end_count = $totalrows;
} elseif ($totalrows - $start >= $pagelimit) {
$end_count = $start + ($pagelimit-1);
}
echo "Displaying $starting_no to $end_count of $totalrows records.<br><br>";
// create dynamic next, previous, and page links
if ($totalrows - $end_count > $pagelimit) {
$var2 = $pagelimit;
} elseif ($totalrows - $end_count <= $pagelimit) {
$var2 = $totalrows - $end_count;
}
$space = " ";
// output your data
$strSQL = OCIParse($conn,"SELECT * FROM(SELECT y.name,w.year,ROWNUM rn FROM uia.alumni_info x,uia.student_st y,uia.acad z,uia.graduate w where x.matric_no = w.matric_no and x.matric_no = y.matric_no and y.acad_prog1 = z.acad_code and z.kuliyyah = 'ENGIN') where rn BETWEEN $start AND $limit");
OCIExecute($strSQL);
while (OCIFetch($strSQL)) {
$name = OCIResult($strSQL,1);
$matric_no = OCIResult($strSQL,2);
//$year = OCIResult($strSQL,3);
?>
<div align="center">
<table width="57%" border="1">
<tr>
<td width="75%"><? echo $name; ?></td>
<td width="25%"></td>
</tr>
</table>
<? }
echo "<br>";
// previous link
if ($page>1) {
echo "ยซ <a href='8.php?page=".($page-1)."'>Previous" . $space . $pagelimit . "</a>" . $space . $space . "";
}
// dynamic page number links
for ($i=1; $i<=$pagenums; $i++) {
if ($i!=$page) {
echo " <a href='8.php?page=$i'>$i</a>";
}
else {
echo "$i";
}
}
// next link
if ($page<$pagenums) {
echo "" . $space . $space . $space . $space . " <a href='8.php?page=".($page+1)."'>Next " . $var2 . "</a> ยป<br><br>";
}
?>
๐