phpwiz Posted August 25, 2009 Share Posted August 25, 2009 Ok, i have a code for my comments using pagintation but i just want to display the number of pages like intead of next/prev and also i want to put the number of pages in the table i have where it says "next" but i also want to be able to put the number of the pages and links anywhere else on the page can you please help me do this it would be AMAZING. here is the code. <html> <head> <title>Website</title> <style type='text/css'> body { background: #333333; } #container { width: 905px; <!-- border-style: solid; border-width: 1px; border-color: white; --> } .banner { background-image: url('images/banner.png'); width: 900px; height: 132px; } .cen { background-image: url('images/Comment_top.png'); width: 494px; height: 18px; text-align: center; color: #000000; font-family: arial; font-size: 13px; } .Nav_L { background-image: url('images/N_head.png'); width: 200px; height: 17px; text-align: center; color: #000000; font-family: arial; font-size: 13px; float: left; } .Nav_R { background-image: url('images/N_head.png'); width: 200px; height: 17px; text-align: center; color: #000000; font-family: arial; font-size: 14px; float: right; } .nav { text-align: center; background-image: url('images/Nav.png'); text-decoration: none; font-family: verdana; height: 18px; width: 200px; font-size: 10px; display: block; } .solid { border: 1px solid black; border-left: 1px solid black; border-top: 1px solid black; color: black; font-family: verdana; border-right: 1px solid black; border-bottom: 1px solid black; } .padding { padding: 5px; } </style> <head> <body> <center> <?php include("BBcode.php"); //connecting to the database $error = "Could not connect to the database"; mysql_connect('localhost','root','') or die($error); mysql_select_db('comments') or die($error); //max displayed per page $per_page = 1; //get start variable $start = $_GET['start']; //count records $record_count = mysql_num_rows(mysql_query("SELECT * FROM comments")); //count max pages $max_pages = $record_count / $per_page; //may come out as decimal if (!$start) $start = 0; //display data $get = mysql_query("SELECT * FROM comments LIMIT $start, $per_page"); while ($row = mysql_fetch_assoc($get)) { // get data $id = $row ['id']; $body = $row ['body']; $date = $row ['date']; $postee = $row ['poster']; $time = $row ['time']; $avatar = $row ['avatar']; echo "<div class='cen'>Comment</div>"; echo "<table width='494px' class='solid'>"; echo " <tr bgcolor='#D0D0D0'> <td colspan='2' width='5px'><font size='2'><center><u>Avatar:</u></td> <td colspan='2'><font size='2'><center>Posted By:"; echo $postee; echo "</td> </tr> <tr bgcolor='#FFFFFF'> <td colspan='2' width='21%'><font size='2'><center><img src='$avatar'></td> <td colspan='2' class='padding' valign='top'><font size='2' face='verdana'>"; echo nl2br(bbcode_format(strip_tags($body))); echo "</td> </tr> <tr bgcolor='#D0D0D0'> <td colspan='2' width='5px'><font size='2'><center>Options</td> <td colspan='2'><font size='2'><center><a href='#'>Modify</a> <a href='#'>Delete</a> <a href='#'>Quote</a></td> </tr> <tr bgcolor='#D0D0D0'> <td colspan='2' width='5px'><font size='2'><center><u>Date:</u></td> <td colspan='2'><font size='2'><center>"; echo $date; echo "</td> </tr> <tr bgcolor='#D0D0D0'> <td colspan='2' width='5px'><font size='2'><center><u>Time:</u></td> <td colspan='2'><font size='2'><center>"; echo $time; echo "</td> </tr> "; echo "</table>"; echo "<br>"; } //setup prev and next variables $prev = $start - $per_page; $next = $start + $per_page; //show prev button if (!($start<=0)) echo "<a href='omg.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='omg.php?start=$x'>$i</a> "; else echo " <a href='omg.php?start=$x'><b>$i</b></a> "; $i++; } //show next button if (!($start>=$record_count-$per_page)) { echo " <div class='Cen'>Pages</div> <table class='solid'> <tr bgcolor='#FFFFFF'> <td width='486px'><center> <a href='omg.php?start=$next'>Next</a> </td> </tr> </table> "; } else { } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
phpwiz Posted August 25, 2009 Author Share Posted August 25, 2009 Ok i think i am going blind, lol i dont know how to edit my post but i wanted to say that can you also check out my css post here Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted August 25, 2009 Share Posted August 25, 2009 to display each page you need to figure out how many pages of data you have. $total_num_pages = ceil($record_count / $records_per_page); You already have something like above but you should round it up also. Then set a variable with your current page looks like this is your start variable and then whenever you want to display your page numbers simply loop through each page <?php for($i=0; $i<$total_num_pages; $i++) { echo "<a href='?start=" . $i . "'>" . $i . "</a>" } ?> Quote Link to comment Share on other sites More sharing options...
phpwiz Posted August 25, 2009 Author Share Posted August 25, 2009 not what i am looking for Quote Link to comment Share on other sites More sharing options...
Infected.Shadow Posted August 25, 2009 Share Posted August 25, 2009 not what i am looking for Well perhaps you could elaborate on what you are looking for? Do you mean like: [Prev] 1 - 2 - 3 ... - 10 -11 [Next] ? Quote Link to comment Share on other sites More sharing options...
phpwiz Posted August 25, 2009 Author Share Posted August 25, 2009 not what i am looking for Well perhaps you could elaborate on what you are looking for? Do you mean like: [Prev] 1 - 2 - 3 ... - 10 -11 [Next] ? ok exactly what i want is here go to http://tpa-rpg.co.cc click the splash, make an account, login and go on the left menu where it says "news comments" then under where it displays the news it shows how many pages of comments there are. i already know how to display the news and stuff but i want to be able to display the "comment pages" where ever i want on my web page. if that makes sense. Quote Link to comment Share on other sites More sharing options...
Infected.Shadow Posted August 25, 2009 Share Posted August 25, 2009 not what i am looking for Well perhaps you could elaborate on what you are looking for? Do you mean like: [Prev] 1 - 2 - 3 ... - 10 -11 [Next] ? ok exactly what i want is here go to http://tpa-rpg.co.cc click the splash, make an account, login and go on the left menu where it says "news comments" then under where it displays the news it shows how many pages of comments there are. i already know how to display the news and stuff but i want to be able to display the "comment pages" where ever i want on my web page. if that makes sense. So you're looking to paginate the comments? Just apply what Bendude14 said to your comments section of your code. Quote Link to comment Share on other sites More sharing options...
phpwiz Posted August 25, 2009 Author Share Posted August 25, 2009 not what i am looking for Well perhaps you could elaborate on what you are looking for? Do you mean like: [Prev] 1 - 2 - 3 ... - 10 -11 [Next] ? ok exactly what i want is here go to http://tpa-rpg.co.cc click the splash, make an account, login and go on the left menu where it says "news comments" then under where it displays the news it shows how many pages of comments there are. i already know how to display the news and stuff but i want to be able to display the "comment pages" where ever i want on my web page. if that makes sense. So you're looking to paginate the comments? Just apply what Bendude14 said to your comments section of your code. i was trying to work it out with him on msn and he logged out i really have no idea how to do this if you could like show me. here is the entire code i have so far: <html> <head> <title>comments</title> <style type='text/css'> body { background: #333333; } #container { width: 905px; <!-- border-style: solid; border-width: 1px; border-color: white; --> } .banner { background-image: url('images/banner.png'); width: 900px; height: 132px; } .cen { background-image: url('images/Comment_top.png'); width: 494px; height: 18px; text-align: center; color: #000000; font-family: arial; font-size: 13px; } .Nav_L { background-image: url('images/N_head.png'); width: 200px; height: 17px; text-align: center; color: #000000; font-family: arial; font-size: 13px; float: left; } .Nav_R { background-image: url('images/N_head.png'); width: 200px; height: 17px; text-align: center; color: #000000; font-family: arial; font-size: 14px; float: right; } .nav { text-align: center; background-image: url('images/Nav.png'); text-decoration: none; font-family: verdana; height: 18px; width: 200px; font-size: 10px; display: block; } .solid { border: 1px solid black; border-left: 1px solid black; border-top: 1px solid black; color: black; font-family: verdana; border-right: 1px solid black; border-bottom: 1px solid black; } .padding { padding: 5px; } .padding1 { padding: 2px; } </style> <head> <body> <center> <?php include("BBcode.php"); //connect to database mysql_connect('localhost','root','') or die(mysql_error()); mysql_select_db('comments') or die(mysql_error()); //max displayed per page $per_page = 1; //get start variable $start = $_GET['start']; //count records $record_count = mysql_num_rows(mysql_query("SELECT * FROM comments")); //count max pages $max_pages = $record_count / $per_page; //may come out as decimal if (!$start) $start = 0; //display data //query the db $getnews = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 1") or die(mysql_error()); while ($row1 = mysql_fetch_assoc ($getnews) ) { //get data $id1 = $row1 ['id']; $title1 = $row1 ['title']; $body1 = $row1 ['body']; $date1 = $row1 ['date']; $time1 = $row1 ['time']; $avatar1 = $row1 ['avatar']; $postee1 = $row1 ['postee']; echo "<div class='cen'><div class='padding1'>News Subject: <b> "; echo $title1; echo "</b></div></div>"; echo "<table class='border1' width='494px'>"; echo " <tr bgcolor='#D0D0D0'> <td colspan='2' width='5px'><font size='2'><center><u>Avatar</u></td> <td colspan='2'><font size='2'><center>News Post</td> </tr> <tr bgcolor='#FFFFFF'> <td colspan='2' width='21%'><font size='2'><center><img src='$avatar1'></td> <td colspan='2' class='padding' valign='top'><font size='2' face='verdana'>"; echo nl2br(bbcode_format(strip_tags($body1))); echo "</td> </tr> <tr bgcolor='#D0D0D0'> <td colspan='2' width='5px'><font size='2'><center>Options</td> <td colspan='2'><font size='2'><center><a href='#'>Modify</a> <a href='#'>Delete</a> <a href='#'>Quote</a></td> </tr> <tr bgcolor='#D0D0D0'> <td colspan='2' width='5px'><font size='2'><center><u>Date:</u></td> <td colspan='2'><font size='2'><center>"; echo $date1; echo "</td> </tr> <tr bgcolor='#D0D0D0'> <td colspan='2' width='5px'><font size='2'><center><u>Time:</u></td> <td colspan='2'><font size='2'><center>"; echo $time1; echo "</td> </tr> "; echo "</table>"; echo "<br>"; } echo "<div class='cen'><div class='padding1'>Pages Of Comments</div></div>"; echo "<table width='494px' class='border1'>"; echo " <tr bgcolor='#FFFFFF'> <td> <center><font size='2' face='verdana'>Number of pages inside of here.</font></center> </td> </tr> "; echo "</table>"; echo "<br />"; $get = mysql_query("SELECT * FROM comments LIMIT $start, $per_page"); while ($row = mysql_fetch_assoc($get)) { // get data $id = $row ['id']; $body = $row ['body']; $date = $row ['date']; $postee = $row ['poster']; $time = $row ['time']; $avatar = $row ['avatar']; echo "<div class='cen'><div class='padding1'>Comment</div></div>"; echo "<table width='494px' class='solid'>"; echo " <tr bgcolor='#D0D0D0'> <td colspan='2' width='5px'><font size='2'><center><u>Avatar:</u></td> <td colspan='2'><font size='2'><center>Posted By:"; echo $postee; echo "</td> </tr> <tr bgcolor='#FFFFFF'> <td colspan='2' width='21%'><font size='2'><center><img src='$avatar'></td> <td colspan='2' class='padding' valign='top'><font size='2' face='verdana'>"; echo nl2br(bbcode_format(strip_tags($body))); echo "</td> </tr> <tr bgcolor='#D0D0D0'> <td colspan='2' width='5px'><font size='2'><center>Options</td> <td colspan='2'><font size='2'><center><a href='#'>Modify</a> <a href='#'>Delete</a> <a href='#'>Quote</a></td> </tr> <tr bgcolor='#D0D0D0'> <td colspan='2' width='5px'><font size='2'><center><u>Date:</u></td> <td colspan='2'><font size='2'><center>"; echo $date; echo "</td> </tr> <tr bgcolor='#D0D0D0'> <td colspan='2' width='5px'><font size='2'><center><u>Time:</u></td> <td colspan='2'><font size='2'><center>"; echo $time; echo "</td> </tr> "; echo "</table>"; echo "<br>"; } //setup prev and next variables $prev = $start - $per_page; $next = $start + $per_page; //show prev button if (!($start<=0)) echo "<a href='omg.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='omg.php?start=$x'>$i</a> "; else echo " <a href='omg.php?start=$x'><b>$i</b></a> "; $i++; } //show next button if (!($start>=$record_count-$per_page)) { echo " <div class='Cen'>Pages</div> <table class='solid'> <tr bgcolor='#FFFFFF'> <td width='486px'><center> <a href='omg.php?start=$next'>Next</a> </td> </tr> </table> "; } else { } ?> </body> </html> can you please just show me so i can learn from that since i am a visual learner. Quote Link to comment Share on other sites More sharing options...
phpwiz Posted August 25, 2009 Author Share Posted August 25, 2009 can anyone help :/? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.