ArizonaJohn Posted May 21, 2009 Share Posted May 21, 2009 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"; } Link to comment https://forums.phpfreaks.com/topic/159139-splitting-up-an-html-table-into-50-row-sections/ Share on other sites More sharing options...
Ken2k7 Posted May 21, 2009 Share Posted May 21, 2009 I think you're looking for pagination. Read this - http://www.phpfreaks.com/tutorial/basic-pagination Link to comment https://forums.phpfreaks.com/topic/159139-splitting-up-an-html-table-into-50-row-sections/#findComment-839277 Share on other sites More sharing options...
tibberous Posted May 21, 2009 Share Posted May 21, 2009 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. Link to comment https://forums.phpfreaks.com/topic/159139-splitting-up-an-html-table-into-50-row-sections/#findComment-839285 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.