Forum Moderators: coopster
So that it will display somethign like below
Previous 0 1 2 3 4 5 6 7 Next
I tried the sample example listed below but it didnt seem to work?
does anyone havea working example?
Thanks
Here is the example and out is listed below
$page = (!isset($_GET['page']))? 1 : $_GET['page'];
$prev = ($page - 1);
$next = ($page + 1);
/* Max results per page */
$max_results = 5;
/* Calculate the offset */
$from = (($page * $max_results) - $max_results);
/* Query the db for total results. You need to edit the sql to fit your needs */
//$result = mysql_query("SELECT * FROM content_items_2");
$sql1 ="select * from content_items_2";
$result=sqlresult($sql1);
$total_results = mysql_num_rows($result);
echo " totla results : $total_results <br>";
$total_pages = ceil($total_results / $max_results);
echo " totla pages : $total_pages <br>";
$pagination = '';
/* Create a PREV link if there is one */
if($page > 1)
{
$pagination .= '<a href="demo.php?page='.$prev.'">Previous</a> ';
}
/* Loop through the total pages */
for($i = 1; $i <= $total_pages; $i++)
{
if(($page) == $i)
{
$pagination .= $i;
}
else
{
$pagination .= '<a href="demo.php?page='.$i.'">$i</a>';
}
}
/* Print NEXT link if there is one */
if($page < $total_pages)
{
$pagination .= '<a href="demo.php?page='.$next.'">Next</a>';
}
$sql2 ="select * from content_items_2";
$sql2.=" LIMIT $from, $max_results ";
$result2=sqlresult($sql2);
echo "sql2:$sql2<br>";
echo "result2 :$result2<br>";
print_r($result2);
//$row = mysql_fetch_array(result);
?>
<form method="post" action="pr_selected.php">
<table border ="0" bordercolor=#000000 bgcolor="#FFFFFF" align-"center"i width=700>
<!--------------------------------------------------tr>
<td><input type="checkbox" onClick="Checkall(this.form);" />check all( Use this to select/deselect items in list)<br />
</td> <td> </td>
</tr---------------------------------------->
<tr >
<td valign=top NOWRAP><input type="checkbox" onClick="Checkall(this.form);" />check all( Use this to select/deselect items in list)<br /></td>
</tr>
<tr>
<td>
<!----table width=750 border=0----------->
<table id="classinfo" summary="Class Information" >
<tr>
<th> </th>
<th>Id </th>
<th>Title </th>
<th>Abstract </th>
<th>Teaser </th>
<!--th>Path </th--------->
<th>Type </th>
<th>Status </th>
<!---------th>Uid </th>
<th>Start Date </th>
<th>End Date </th----------------->
<th>Publishing Date </th>
<th>Promote </th>
<th>Created Date</th>
<th>Modified Date </th>
</tr>
<?
while ($row = mysql_fetch_array($result2)) {
$RowColor=useColor();
echo "<tr > ";
echo "<td Valign=top NOWRAP BGCOLOR=> <input type=\"checkbox\" value=".$row["iid"]." name=\"iid[]\"> </td>";
echo " <td VALIGN=top BGCOLOR=> ".$row["iid"]." </td> ";
echo " <td VALIGN=top NOWRAP BGCOLOR=> ".$row["title"]."<a href =\"javascript:void window.open('http://www.accessintel.com', 'Template', 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=no, scrollbars=yes, width=600, height=500')\">(Read More)</a> </td>";
echo " <td VALIGN=top BGCOLOR=> ".$row["abstract"]."</td>";
echo " <td VALIGN=top BGCOLOR=> ".$row["teaser"]."</td>";
/*echo " <td VALIGN=top BGCOLOR=> ".$row["path"]." <a href =\"javascript:void window.open('http://www.accessintel.com', 'Template', 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=no, scrollbars=yes, width=600, height=500')\">(Read More)</a> </td>";
*/
echo " <td VALIGN=top BGCOLOR=> ".$row["type"]."</td>";
echo " <td VALIGN=top NOWRAP BGCOLOR=> ".$row["status"]."</td>";
//echo " <td VALIGN=top NOWRAP BGCOLOR=> ".$row["uid"]."</td>";
echo " <td VALIGN=top NOWRAP BGCOLOR=> ".$row["pubdate"]."</td>";
echo " <td VALIGN=top NOWRAP BGCOLOR=> ".$row["promote"]."</td>";
echo " <td VALIGN=top NOWRAP BGCOLOR=> ".$row["created"]."</td>";
echo " <td VALIGN=top NOWRAP BGCOLOR=> ".$row["modified"]."</td>";
echo "</tr>";
}
?>
</table>
</td> </tr>
<tr>
<td>
<input type="submit" name="Approve" value="Approve" class="demo4" onmouseover="hov(this,'demo4 btnhov')" onmouseout="hov(this,'demo4')" />
<input type="submit" name="Bounce" value="Bounce" class="demo4" onmouseover="hov(this,'demo4 btnhov')" onmouseout="hov(this,'demo4')" />
<input type="submit" name="Hold" value="On Hold" class="demo4" onmouseover="hov(this,'demo4 btnhov')" onmouseout="hov(this,'demo4')" />
</td>
</tr>
</table>
<br>
</form>
<?
echo "<br> $pagination";
include "footer.inc";
?>
OUTPUT
1$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$ i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$ i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$ i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$ i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$ i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$ i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$ i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$i$iNext
[edited by: jatar_k at 9:03 pm (utc) on Aug. 16, 2005]
[edit reason] fixed sidescroll [/edit]
if(!function_exists('my_pagination')) //Return HTML to echo{
function my_pagination($currentPage, $perPage, $pages, $amount, $link){
if($page_max = ceil($amount/$perPage)) {
if($currentPage > 1) {
$prev = $currentPage - 1;
$text = "<a href=\"".$link.".?page=1\" target=\"_top\">First </a><a href=\"".$link.".?page=$prev\" target=\"_top\">Previous </a>"; }
$k = $currentPage; $i = 0;
while($k > 1) {//this is to have the current page in the middle
$k--; $i++; if($i == floor($pages/2 - 1)) break; }
for($i = 0; $i < $pages; $i++) { if($k > $page_max) break;
if($k!= $currentPage) $text .="<a href=\"".$link.".?page=$k\" target=\"_top\">$k </a> ";
else $text .=" [$k] "; $k++; }
if($page_max > $currentPage) {
$next = $currentPage + 1; $text .="<a href=\"".$link.".?page=$next\" target=\"_top\">Next </a><a href=\"".$link.".?page=$page_max\" target=\"_top\">Last </a>";
}} return $text; }}
$page = (!(int)($_GET['page']))? 1 : (int)$_GET['page'];//be sure it's numeric!
//get all records number here! $amount = mysql_num_rows($result);
$text_choosePage = my_pagination($page, 20, 10, $amount, "index.html");
$pagination .= '<a href="demo.php?page='.$i.'">'.$i.'</a>';
or
$pagination .= "<a href=\"demo.php?page=$i\">$i</a>";
Best regards
Michal Cibor
PS. If you put variable in quotes ' ' it is processed as a text. In double quotes " " it is processed as a variable (doesn't include arrays and objects)