Jump to content

Splitting up an HTML table into 50 row sections


ArizonaJohn

Recommended Posts

Hello,

 

The code below returns an HTML table from a MySQL database.  It works great.  However, if there is a table that has more than 50 rows, I would like to split it up into sections.  I would like each section to only have 50 rows, and I would like only 50 rows displayed at a time.  Ideally, I would like a hyperlink which the user could click to see the next 50 rows, and I would like these hyperlinks to be numbered 1, 2, 3, etc.

 

Is this something that can be done easily?  If so, how would I go about doing it?

 

Thanks in advance,

 

John

 

$result=mysql_query("SHOW TABLES FROM sand2 LIKE '%$find%'")
or die(mysql_error());

if(mysql_num_rows($result)>0){
while($table=mysql_fetch_row($result)){
print "<p class=\"topic\">$table[0]</p>\n";
$r=mysql_query("SELECT * , votes_up - votes_down AS effective_vote FROM `$table[0]` ORDER BY effective_vote DESC");

print "<table class=\"navbar\">\n";
while($row=mysql_fetch_array($r)){

$effective_vote = $row['votes_up'] - $row['votes_down']; 

print "<tr>";

print "<td>".'<a href="http://'.$row['site'].'" class="links2">'.$row['site'].'</a>'."</td>";
print "<td class='votes'>".'<span class="votes_count" id="votes_count'.$row['id'].'">'.number_format($effective_vote).'</span>'."</td>";
print "<td class='ballot'>".'<span class="button" id="button'.$row['id'].'">'.'<a href="javascript:;" class="cell1" id="'.$row['id'].'">'.Vote.'</a>'.'</span>'."</td>";
}
print "</tr>\n";
}
print "</table>\n";
}
else{
print "None found";
}

Yeah, that's pagination.

 

Basically you figure out the total number or rows your going to show, then divide it by the number you want per page, and end up with the number of pages you want. Then you make a link for each page you having, and pass each one something like ?page=3. Then, then you do your mysql query, you do a limit X, 50, where X is the page they are on, times the number per page.

 

Start at page 0, not one. That way the first page starts at (50 * 0), which is 0, which is the first record.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.