dephekt
09-06-2004, 09:55 AM
hi guys. im kind of new to php. i've got a little problem with some paging issues.
im kind of using this code:
<?
include_once("admin/conn.php");
//$page=1;
$ct1=0;
$ct2=0;
//$perpage=5;
//$prop_id="prop_id";
//paging defaults
if(!$page){$page=1;}
if(!$perpage){
//$perpage can be passed in a query string to change the records per page (?perpage=10)
$perpage=15;//how many records per page default to 5
}
function page_records($page,$pagecount,$recordstart,$COLUMN_NAME,$SEARCH_TERM,$perpage,$totalreturned){
$ct1=(($page-1)*$perpage)+1;
$ct2=$ct1+($perpage-1);
if ($totalreturned<$ct2) {
$ct2=$totalreturned;
}
?>
and this to list the pages:
<?php }
page_records($page,$pagecount,$recordstart,$COLUMN_NAME,$SEARCH_TERM,$perpage,$totalreturned);
?>
<?php
}
else
{
//page_records($page,$pagecount,$recordstart,$COLUMN_NAME,$SEARCH_TERM,$perpage,$totalreturned);
// }
//else
//echo "No record"; ?>
this gives me paging in the form of
1 2 3 4 5 6 7 8 9 10 and so on.
how do i make it into something like this??
1 2 3 4 5 6 7 8 9 10 11 Next>
<Previous 2 3 4 5 6 7 8 9 10 11 Next>
thanks alot in advance.
azizny
09-06-2004, 03:04 PM
Hmmm... hard logic... I mostly use this:
ONTOP OF PAGE:
<?
$display = '10';
$count = @mysql_num_rows(@mysql_query("SELECT * FROM islamic WHERE title LIKE '%$search%'"));
if(isset($_GET['np'])) {
$num_pages = $_GET['np'];
} else {
$num_records = $count;
if($num_records > $display) {
$num_pages = ceil ($num_records/$display);
} else {
$num_pages = 1;
}
}
if(isset($_GET['s'])){
$start = $_GET['s'];
} else {
$start = 0;
}
$get_show_list = @mysql_query($all_query . " LIMIT $start,$display");
?>
VIEW THE NUMBERS:
<?
<? if ($count > 0){?>
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td><div align="center"><font size="3"><strong><font face="Times New Roman, Times, serif"> </font></strong></font><font size="3"><strong><font face="Times New Roman, Times, serif">
<? if($start <= 0){ $show_s = 1;} else { $show_s = $start+1;}
if($display+$start > $count || $display+$start <= 0){ $dis_c = $count;} else { $dis_c = $display+$start;}?>
&Viewing items <? echo $show_s;?> to <? echo $dis_c;?> &&&&&&</font></strong></font>
<?
if($count > $display){
$current_page = ($start/$display)+1;
if($current_page != 1) {
echo '<a href="' . $_SERVER[PHP_SELF]. '?s=' . ($start-$display) . '&np=' . $num_pages . '&view_limit=' . $display . '&album_name=' . $_POST[album_name] . '&sort_by=' . $_POST[sort_by] . '&sort_type=' . $_POST[sort_type] . '" class="link">Previous</a>';
}
for ($i = 1; $i <= $num_pages ; $i++) {
if($i != $current_page){
echo ' [<a href="' . $_SERVER[PHP_SELF]. '?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&view_limit=' . $display . '&album_name=' . $_POST[album_name] . '&sort_by=' . $_POST[sort_by] . '&sort_type=' . $_POST[sort_type] . '" class="link" >' . $i . '</a>] ';
} else {
echo '<font color="gray"> [' . $i . '] </font>';
}
}
if($current_page != $num_pages){
echo '<a href="' . $_SERVER[PHP_SELF]. '?s=' . ($start+$display) . '&np=' . $num_pages . '&view_limit=' . $display . '&album_name=' . $_POST[album_name] . '&sort_by=' . $_POST[sort_by] . '&sort_type=' . $_POST[sort_type] . '" class="link" >Next</a>';
}
}
?>
?>
SHOW RESULTS:
<?
while($get_nums = @mysql_fetch_array($get_show_list)){
echo $get_nums['title'];
}
?>
EXOWorks
09-06-2004, 10:55 PM
page_records() doesnt returns anything so how are you getting the output ???
VolkNet
09-07-2004, 02:52 AM
For what it helps heres kinda the core of a script i wrote. Maybe it will help you out to understand how i did mine.
else if($counted > 1) / /basically if more then one page form above
{
$counted = ceil($counted); // makes 1.12 page = 2 page lol and etc.
echo "<center><font size=\"-1\" face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"#990000\">Select a Page<br />";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev&cat=$cat\"><B>PREVIOUS</b></a> ";
}
for($i = 1; $i <= $counted; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&cat=$cat\"><b>$i</b></a> ";
}
}
// Build Next Link
if($page < $counted){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next&cat=$cat\"><b>NEXT</b></a>";
}
echo "</font></center>";
If you kinda go through the snippit of code i use here, you can see that i passed the page variable through the url and used a for loops to check to see what was what. :) hope this helps!