Current location: Hot Scripts Forums » Programming Languages » PHP » pagination within a html table


pagination within a html table

Reply
  #1 (permalink)  
Old 11-17-09, 05:24 PM
balamberas balamberas is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
pagination within a html table

Hi, im trying to insert this code within a html script but the Prev 1 2 3 4 next is not displayed and also the DESC is to responding. Any Ideas?
PHP Code:

<?php

include ("connect.php");


// max display per page

$per_page 50;

// get start variable

$start $_GET ['start'];

// count record

$record_count mysql_num_rows (mysql_query("SELECT * FROM flats ORDER BY date_posted DESC")); 

//count max pages

$max_pages $record_count $per_page// may come out as a decimal

if (!$start)

  
$start 0;

// display data
$get mysql_query("SELECT * FROM flats LIMIT $start$per_page");
 
   while (
$row mysql_fetch_assoc($get))
   
 {
 
  
// get data 

   
$select$row['type'];
   
$title$row['title'];
   
$location$row['location'];
  

    echo 
"<div><b>$title</b></div>";
    echo 
"<br>";
    echo 
"$select";
    echo 
"<br>";
    echo 
"$rent";
    echo 
"<br>";
    echo 
"$location";
  

}

// setup the prev and next variables

$prev $start $per_page

$next $start $per_page;

//show prev button

if (!($start<=0)) 

  echo 
" <a href='londonfc_flats.php?start=$prev'> << Prev </a> ";

//show page numbers

// set variable for first page

$i=1;

for (
$x=0;$x<$record_count;$x=$x+$per_page)
{

 if (
$start!=$x)
   
  echo 
" <a href='londonfc_flats.php?start=$x'>$i |</a> ";

else 
  echo 
" <a href='londonfc_flats.php?start=$x'><b> $i|</b></a> ";

$i++;

}

//show next button

 
if (!($start>=$record_count-$per_page))
 echo 
" <a href='londonfc_flats.php?start=$next'> Next >></a> "


?>

Last edited by job0107; 11-18-09 at 08:41 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-18-09, 09:05 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
It works when I try it.
The only thing is, the Prev 1 2 3 4 next are being displayed on the same line as $location.
Put a <p> after that line and you will see the page navigation.
PHP Code:

echo "<div><b>$title</b></div>
      <br>
      
$select
      <br>
      
$rent
      <br>
      
$location
      <p>"

Also you have your ORDER BY clause in the wrong query.
Remove it from the first query and put it in the second query.

I am sure you can do this with only one query if you think it through.
__________________
Jerry Broughton

Last edited by job0107; 11-18-09 at 09:11 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-18-09, 04:03 PM
balamberas balamberas is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
Hi, the pagination is ok when its outside this html table. but within it the Prev 1 2 3 4 Next is not showing. i tried the "<p>" but no luck.
PHP Code:

<table width="487" height="672"  border="1" align="left" cellpadding="3" cellspacing="3" background="/bgtr.gif">
                <tr align="center" valign="middle"> 
                  <td width="23%" height="28" bgcolor="#FFFFFF"> <h3 align="center">Available 
                     </h3></td>
                </tr>
                <tr align="center" valign="middle"> 
                  <td height="626" align="left" valign="top" bgcolor="#FFFFFF"> 
                             

<?php

include ("connect.php");


// max display per page

$per_page 50;

// get start variable

$start $_GET ['start'];

// count record

$record_count mysql_num_rows (mysql_query("SELECT * FROM flats"));

//count max pages

$max_pages $record_count $per_page// may come out as a decimal

if (!$start)

  
$start 0;

// display data 

$get mysql_query("SELECT * FROM flats ORDER BY date_posted DESC LIMIT $start$per_page");
 
   while (
$row mysql_fetch_assoc($get))
   
 {
 
  
// get data 

   
$select$row['type'];
   
$title$row['title'];
   
$location$row['location'];
  

    echo 
"<div><b>$title</b></div>";
    echo 
"<br>";
    echo 
"$select";
    echo 
"<br>";
    echo 
"$rent";
    echo 
"<br>";
    echo 
"$location";
        
"<p>";
}

// setup the prev and next variables

$prev $start $per_page

$next $start $per_page;

//show prev button

if (!($start<=0)) 

  echo 
" <a href='londonfc_flats.php?start=$prev'><b> «« Prev </b></a> ";

//show page numbers

// set variable for first page

$i=1;

for (
$x=0;$x<$record_count;$x=$x+$per_page)
{

 if (
$start!=$x)
   
  echo 
" <a href='londonfc_flats.php?start=$x'>$i |</a> ";

else 
  echo 
" <a href='londonfc_flats.php?start=$x'><b> $i|</b></a> ";

$i++;

}

//show next button

 
if (!($start>=$record_count-$per_page))
 echo 
" <a href='londonfc_flats.php?start=$next'><b> Next »»</b></a> "


?>




                  </td>
                </tr>
              </table>

Last edited by job0107; 11-19-09 at 11:30 AM. Reason: Please use bb code tags around your code
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-19-09, 11:40 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Try it like this:
PHP Code:

<html>
<head>
<style>
.table1
{
 border-collapse:collapse;
 }
.table2
{
 width:100%;border:none;border-collapse:collapse;
 }
.table3
{
 height:20px;
 width:100%;
 }
.title
{
 text-align:center;
 font-size:18px;
 font-weight:bold;
 background:#fff;
 }
.td_header
{
 width:25%;
 text-align:center;
 font-size:16px;
 font-weight:bold;
 }
.div_header_1
{
 margin-left:2px;
 margin-right:1px;
 background:#fff;
 }
.div_header_2
{
 margin-left:1px;
 margin-right:1px;
 background:#fff;
 }
.div_header_3
{
 margin-left:1px;
 margin-right:2px;
 background:#fff;
 }
.row_style_tr
{
 text-align:center;
 font-size:14px;
 }
.row_style_td
{
 width:25%;
 background:#fff;
 border:1px solid #000;
 }
span
{
 background:#fff;
 }
</style>
<?php
include ("connect.php");
$per_page 50;
$start $_GET ['start'];
$record_count mysql_num_rows (mysql_query("SELECT * FROM flats "));
$max_pages $record_count $per_page// may come out as a decimal
if(!$start){$start 0;}
$get mysql_query("SELECT * FROM flats ORDER BY date_posted DESC LIMIT $start$per_page");
?>
</head>
<body>
<table width="487px" height="672px" border="0" cellpadding="3" cellspacing="0" background="/bgtr.gif" class="table1">
 <tr>
  <td>
   <table cellpadding="0" cellspacing="0" class="table2">
    <tr class="title">
     <td>Available</td>
    </tr>
   </table>
  </td>
 </tr>
 <tr height="20px">
  <td>
   <table cellpadding="0" cellspacing="0" class="table2">
    <tr>
     <td class="td_header"><div class="div_header_1">Title</div></td>
     <td class="td_header"><div class="div_header_2">Type</div></td>
     <td class="td_header"><div class="div_header_2">Rent</div></td>
     <td class="td_header"><div class="div_header_3">Location</div></td>
    </tr>
   </table>
  </td>
 </tr>
 <tr valign="top" height="592px">
  <td>
   <table cellpadding="0" cellspacing="0" class="table2">
    <?php
    $prev 
$start $per_page;
    
$next $start $per_page;
    while (
$row mysql_fetch_assoc($get))
    {
     
// get data
     
$select$row['type'];
     
$title$row['title'];
     
$location$row['location'];
     
$rent $row["rent"];
     echo 
"<tr class='row_style_tr'>
            <td class='row_style_td'><b>
$title</b></td>
            <td class='row_style_td'>
$select</td>
            <td class='row_style_td'>$
$rent</td>
            <td class='row_style_td'>
$location</td>
           </tr>"
;
     }
    
?>
   </table>
  </td>
 </tr>
 <tr>
  <td>
   <table class="table3">
    <tr align="right">
     <td><span>
      <?php
      
if($start>0){echo "<a href='londonfc_flats.php?start=$prev'> << Prev </a>";}
      
$i=1;
      for (
$x=0;$x<$record_count;$x=$x+$per_page)
      {
       if(
$start!=$x){echo "<a href='londonfc_flats.php?start=$x'>$i |</a>";}
       else{echo 
"<a href='londonfc_flats.php?start=$x'><b> $i|</b></a>";}
       
$i++;
       }
      if(
$start<$record_count-$per_page){echo "<a href='londonfc_flats.php?start=$next'> Next >></a>";}
      
?>
     </span></td>
    </tr>
   </table>
  </td>
 </tr>
</table>
You should be able to see the navigation links on the bottom.
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to job0107 For This Useful Post:
balamberas (11-24-09)
  #5 (permalink)  
Old 11-24-09, 05:28 AM
balamberas balamberas is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
thanks man. its working fine now.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 11-24-09, 08:09 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Your welcome. Glad I could be of assistance.
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 04-21-11, 11:03 AM
codehelper codehelper is offline
New Member
 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Trophee Html table pagination

Please follow the link below, which will help providing google style paging e.g. 1 to 10, 20 to 30. Below is the link.


Features it will provide:
1. google style pagination.
2. number of records.
3. will hide next and previous when not required.

Follow this link :
Codehelper: Html Table Pagination
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML table cell data insert into database conmen80 PHP 2 05-26-09 10:40 PM
MYSQL database countll Database 2 06-19-07 05:20 PM
accessing DOM HTML Elements in a dynamically built table. drdexter33 JavaScript 3 02-04-06 04:43 PM
Numbering HTML Table rows lppa2004 PHP 11 07-18-05 02:22 PM
Advice parsing a html table to xml RossC0 JavaScript 3 03-22-05 03:10 PM


All times are GMT -5. The time now is 06:52 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.