943,901 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 651
  • PHP RSS
Feb 7th, 2009
0

paging problem ?

Expand Post »
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....

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. include("config.php");
  3. $page_name="index.php";
  4.  
  5. $start=$_GET['start'];
  6. // To take care global variable if OFF
  7. if(!($start > 0)) { // This variable is set to zero for the first page
  8. $start = 0;
  9. }
  10.  
  11.  
  12. $eu = ($start - 0);
  13.  
  14. if(!$limit > 0 ){ // if limit value is not available then let us use a default value
  15. $limit = 10; // No of records to be shown per page by default.
  16. }
  17. $this1 = $eu + $limit;
  18. $back = $eu - $limit;
  19. $next = $eu + $limit;
  20. if($area==""){
  21. /////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
  22. $query2=" SELECT * FROM resorts ORDER BY rname ASC";
  23. $result3=mysql_query($query2);
  24. echo mysql_error();
  25. $nume=mysql_num_rows($result3);
  26.  
  27. $query="SELECT * FROM resorts ORDER BY rname ASC limit $eu, $limit";
  28. $row=mysql_query($query);
  29. echo mysql_error();}
  30. else{
  31. /////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
  32. $query2=" SELECT * FROM resorts where area='$area'";
  33. $result2=mysql_query($query2);
  34. echo mysql_error();
  35. $nume=mysql_num_rows($result2);
  36.  
  37. $query="SELECT * FROM resorts where area='$area' limit $eu, $limit";
  38. $row=mysql_query($query);
  39. echo mysql_error();
  40. }
  41. while($rec=mysql_fetch_array($row))
  42. {
  43. $name=$rec['rname'];
  44. $area=$rec['area'];
  45. $address=$rec['address'];
  46. $cuisine=$rec['cuisine'];
  47. $timings=$rec['timings'];
  48. ?>
  49. <tr>
  50. <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>
  51. <td id="td"><?php echo $address; ?></td>
  52. <td id="td"><?php echo $cuisine; ?></td>
  53. <td id="td"><?php echo $timings; ?></td>
  54. </tr><?php } ?>
  55. </table>
  56. <p>
  57. <?php
  58.  
  59. if(isset($result2)){
  60. echo "<table width='50%' align='right'><tr><td align='left' width='30%'>";
  61. //// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
  62. if($back >=0) {
  63. print "<a href='$page_name?start=$back&limit=$limit&area=$area & c=$c'> PREV </a>";
  64. }
  65. //////////////// Let us display the page links at center. We will not display the current page as a link ///////////
  66. echo "</td><td align=center width='30%'>";
  67. $i=0;
  68. $l=1;
  69. for($i=0;$i < $nume; $i=$i+$limit){
  70. if($i <> $eu){
  71. echo " <a href='$page_name?start=$i&limit=$limit&area=$area & c=$c'> $l </a> ";
  72. }
  73. else { echo "$l";} /// Current page is not displayed as link and given font color red
  74. $l=$l+1;
  75. }
  76.  
  77.  
  78. echo "</td><td align='right' width='30%'>";
  79. ///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
  80. if($this1 < $nume) {
  81. print "<a href='$page_name?start=$next&limit=$limit&area=$area & c=$c'> NEXT </a>";}
  82. echo "</td></tr></table>";
  83.  
  84. }
  85.  
  86. else{
  87.  
  88. echo "<table width='50%' align='right'><tr><td align='left' width='30%'>";
  89. //// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
  90. if($back >=0) {
  91. print "<a href='$page_name?start=$back&limit=$limit'> PREV </a>";
  92. }
  93. //////////////// Let us display the page links at center. We will not display the current page as a link ///////////
  94. echo "</td><td align=center width='30%'>";
  95. $i=0;
  96. $l=1;
  97. for($i=0;$i < $nume;$i=$i+$limit){
  98. if($i <> $eu && $l<=3 ){
  99.  
  100. echo " <a href='$page_name?start=$i&limit=$limit'> $l </a> ";
  101. }
  102.  
  103. elseif($i <> $eu){echo " <a href='$page_name?start=$i&limit=$limit'></a> "; }
  104. else {
  105. echo "&nbsp;&nbsp;";
  106. echo "$l";
  107. } /// Current page is not displayed as link and given font color red
  108. $l=$l+1;
  109. }
  110.  
  111.  
  112. echo "</td><td align='right' width='30%'>";
  113. ///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
  114. if($this1 < $nume) {
  115. print "<a href='$page_name?start=$next&limit=$limit'> NEXT </a>";}
  116. echo "</td></tr></table>";
  117. }
  118. ?>
Similar Threads
Reputation Points: 10
Solved Threads: 7
Junior Poster
sarithak is offline Offline
183 posts
since Aug 2008
Feb 9th, 2009
0

Re: paging problem ?

<?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));?>">&gt;&gt;</a>
<?php
}
?>
</td>
</tr>
<tr><td colspan="3" align="center" valign="middle">&nbsp;</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)))
{
?>
&nbsp;<a class="<?php print($class);?>" href="<?php print("$thispage".($y>0?("?start=").$y:""));?>"><?php print($pg);?></a>&nbsp;
<?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
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
forzadraco is offline Offline
70 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: string case & white spaces problem?
Next Thread in PHP Forum Timeline: PHP mail from mysql





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC