| | |
paging problem ?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2008
Posts: 150
Reputation:
Solved Threads: 6
Hi frns..
here i am going to do paging ...
upto now i got correctly what i mentioned(previous & next ) here...
but i need to add last and first also....
plz see this code with patience....
reply me asap....
here i am going to do paging ...
upto now i got correctly what i mentioned(previous & next ) here...
but i need to add last and first also....
plz see this code with patience....
reply me asap....
PHP Syntax (Toggle Plain Text)
<?php include("config.php"); $page_name="index.php"; $start=$_GET['start']; // To take care global variable if OFF if(!($start > 0)) { // This variable is set to zero for the first page $start = 0; } $eu = ($start - 0); if(!$limit > 0 ){ // if limit value is not available then let us use a default value $limit = 10; // No of records to be shown per page by default. } $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; if($area==""){ /////////////// WE have to find out the number of records in our table. We will use this to break the pages/////// $query2=" SELECT * FROM resorts ORDER BY rname ASC"; $result3=mysql_query($query2); echo mysql_error(); $nume=mysql_num_rows($result3); $query="SELECT * FROM resorts ORDER BY rname ASC limit $eu, $limit"; $row=mysql_query($query); echo mysql_error();} else{ /////////////// WE have to find out the number of records in our table. We will use this to break the pages/////// $query2=" SELECT * FROM resorts where area='$area'"; $result2=mysql_query($query2); echo mysql_error(); $nume=mysql_num_rows($result2); $query="SELECT * FROM resorts where area='$area' limit $eu, $limit"; $row=mysql_query($query); echo mysql_error(); } while($rec=mysql_fetch_array($row)) { $name=$rec['rname']; $area=$rec['area']; $address=$rec['address']; $cuisine=$rec['cuisine']; $timings=$rec['timings']; ?> <tr> <td height="30" id="td"><a href="pdetails.php?c=<?php echo $c; ?> & name=<?php echo $name; ?> & area=<?php echo $area; ?>"><?php echo $name; ?></a><a href="pdetails.php?name=<?php echo $name; ?> & c=<?php echo $c; ?>"></a></td> <td id="td"><?php echo $address; ?></td> <td id="td"><?php echo $cuisine; ?></td> <td id="td"><?php echo $timings; ?></td> </tr><?php } ?> </table> <p> <?php if(isset($result2)){ echo "<table width='50%' align='right'><tr><td align='left' width='30%'>"; //// if our variable $back is equal to 0 or more then only we will display the link to move back //////// if($back >=0) { print "<a href='$page_name?start=$back&limit=$limit&area=$area & c=$c'> PREV </a>"; } //////////////// Let us display the page links at center. We will not display the current page as a link /////////// echo "</td><td align=center width='30%'>"; $i=0; $l=1; for($i=0;$i < $nume; $i=$i+$limit){ if($i <> $eu){ echo " <a href='$page_name?start=$i&limit=$limit&area=$area & c=$c'> $l </a> "; } else { echo "$l";} /// Current page is not displayed as link and given font color red $l=$l+1; } echo "</td><td align='right' width='30%'>"; ///////////// If we are not in the last page then Next link will be displayed. Here we check that ///// if($this1 < $nume) { print "<a href='$page_name?start=$next&limit=$limit&area=$area & c=$c'> NEXT </a>";} echo "</td></tr></table>"; } else{ echo "<table width='50%' align='right'><tr><td align='left' width='30%'>"; //// if our variable $back is equal to 0 or more then only we will display the link to move back //////// if($back >=0) { print "<a href='$page_name?start=$back&limit=$limit'> PREV </a>"; } //////////////// Let us display the page links at center. We will not display the current page as a link /////////// echo "</td><td align=center width='30%'>"; $i=0; $l=1; for($i=0;$i < $nume;$i=$i+$limit){ if($i <> $eu && $l<=3 ){ echo " <a href='$page_name?start=$i&limit=$limit'> $l </a> "; } elseif($i <> $eu){echo " <a href='$page_name?start=$i&limit=$limit'></a> "; } else { echo " "; echo "$l"; } /// Current page is not displayed as link and given font color red $l=$l+1; } echo "</td><td align='right' width='30%'>"; ///////////// If we are not in the last page then Next link will be displayed. Here we check that ///// if($this1 < $nume) { print "<a href='$page_name?start=$next&limit=$limit'> NEXT </a>";} echo "</td></tr></table>"; } ?>
My best wishes ... from my soul ... for everyone!
Keep Smiling....Never Depress
Keep Smiling....Never Depress
•
•
Join Date: Mar 2008
Posts: 70
Reputation:
Solved Threads: 1
<?php
$items = array("red","yellow",
"pink","green",
"purple","blue",
"orange","opal",
"ruby","brown",
"bronze","copper",
"ginger","tope",
"orange","light blue",
"light green","dark yellow",
"grey","black",
"white","gold",
"silver");
$thispage = $PHP_SELF ;
$num = count($items); // number of items in list
$per_page = 2; // Number of items to show per page
$showeachside = 5 // Number of items to show either side of selected page
if(empty($start))$start=0; // Current start position
$max_pages = ceil($num / $per_page); // Number of pages
$cur = ceil($start / $per_page)+1; // Current page number
?>
<style type="text/css">
<!--
.pageselected {
color: #FF0000;
font-weight: bold;
}
-->
</style>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="0" class="PHPBODY">
<tr>
<td width="99" align="center" valign="middle" bgcolor="#EAEAEA">
<?php
if(($start-$per_page) >= 0)
{
$next = $start-$per_page;
?>
<a href="<?php print("$thispage".($next>0?("?start=").$next:""));?>"><<</a>
<?php
}
?>
</td>
<td width="201" align="center" valign="middle" class="selected">
Page <?php print($cur);?> of <?php print($max_pages);?><br>
( <?php print($num);?> records )
</td>
<td width="100" align="center" valign="middle" bgcolor="#EAEAEA">
<?php
if($start+$per_page<$num)
{
?>
<a href="<?php print("$thispage?start=".max(0,$start+$per_page));?>">>></a>
<?php
}
?>
</td>
</tr>
<tr><td colspan="3" align="center" valign="middle"> </td></tr>
<tr>
<td colspan="3" align="center" valign="middle" class="selected">
<?php
$eitherside = ($showeachside * $per_page);
if($start+1 > $eitherside)print (" .... ");
$pg=1;
for($y=0;$y<$num;$y+=$per_page)
{
$class=($y==$start)?"pageselected":"";
if(($y > ($start - $eitherside)) && ($y < ($start + $eitherside)))
{
?>
<a class="<?php print($class);?>" href="<?php print("$thispage".($y>0?("?start=").$y:""));?>"><?php print($pg);?></a>
<?php
}
$pg++;
}
if(($start+$eitherside)<$num)print (" .... ");
?>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<?php
for($x=$start;$x<min($num,($start+$per_page)+1);$x++)print($items[$x]."<br>");
?>
</td>
</tr>
</table>
source: http://www.web-max.ca/PHP/misc_1.php
$items = array("red","yellow",
"pink","green",
"purple","blue",
"orange","opal",
"ruby","brown",
"bronze","copper",
"ginger","tope",
"orange","light blue",
"light green","dark yellow",
"grey","black",
"white","gold",
"silver");
$thispage = $PHP_SELF ;
$num = count($items); // number of items in list
$per_page = 2; // Number of items to show per page
$showeachside = 5 // Number of items to show either side of selected page
if(empty($start))$start=0; // Current start position
$max_pages = ceil($num / $per_page); // Number of pages
$cur = ceil($start / $per_page)+1; // Current page number
?>
<style type="text/css">
<!--
.pageselected {
color: #FF0000;
font-weight: bold;
}
-->
</style>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="0" class="PHPBODY">
<tr>
<td width="99" align="center" valign="middle" bgcolor="#EAEAEA">
<?php
if(($start-$per_page) >= 0)
{
$next = $start-$per_page;
?>
<a href="<?php print("$thispage".($next>0?("?start=").$next:""));?>"><<</a>
<?php
}
?>
</td>
<td width="201" align="center" valign="middle" class="selected">
Page <?php print($cur);?> of <?php print($max_pages);?><br>
( <?php print($num);?> records )
</td>
<td width="100" align="center" valign="middle" bgcolor="#EAEAEA">
<?php
if($start+$per_page<$num)
{
?>
<a href="<?php print("$thispage?start=".max(0,$start+$per_page));?>">>></a>
<?php
}
?>
</td>
</tr>
<tr><td colspan="3" align="center" valign="middle"> </td></tr>
<tr>
<td colspan="3" align="center" valign="middle" class="selected">
<?php
$eitherside = ($showeachside * $per_page);
if($start+1 > $eitherside)print (" .... ");
$pg=1;
for($y=0;$y<$num;$y+=$per_page)
{
$class=($y==$start)?"pageselected":"";
if(($y > ($start - $eitherside)) && ($y < ($start + $eitherside)))
{
?>
<a class="<?php print($class);?>" href="<?php print("$thispage".($y>0?("?start=").$y:""));?>"><?php print($pg);?></a>
<?php
}
$pg++;
}
if(($start+$eitherside)<$num)print (" .... ");
?>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<?php
for($x=$start;$x<min($num,($start+$per_page)+1);$x++)print($items[$x]."<br>");
?>
</td>
</tr>
</table>
source: http://www.web-max.ca/PHP/misc_1.php
http://www.duniaislam.site50.net
Others Social Bookmarking http://www.bisnis-indonesia.org
Business Web Directory
http://www.bisnis-indonesia.biz
Others Social Bookmarking http://www.bisnis-indonesia.org
Business Web Directory
http://www.bisnis-indonesia.biz
![]() |
Similar Threads
- Gridview Paging Problem. (C#)
- Paging Problem (PHP)
- Recordset Paging Problem (ColdFusion)
- paging problem (ASP)
Other Threads in the PHP Forum
- Previous Thread: string case & white spaces problem?
- Next Thread: PHP mail from mysql
| Thread Tools | Search this Thread |
advanced ajax apache api array basics beginner binary broken cakephp check checkbox class cms code combobox cookies cron curl database date datepart display dynamic echo email error file files folder form forms function functions google head href htaccess html image include includingmysecondfileinthechain insert integration ip java javascript job joomla js limit link login mail menu mlm multiple mysql oop parse password paypal pdf php problem procedure query radio random recursion regex remote script search server sessions smarty smash sms soap source space sql stored syntax system table traffic tutorial unicode up-to-date update upload url validator variable video web xml youtube





