nick_whitmarsh Posted July 22, 2007 Share Posted July 22, 2007 Hey guys, I have just gone through the tutorial on this site and cant get pagination to work. Tried Going through my code and still cant get anything. Here is my code concerned. (sorry about the mess guys) Cheers <?php session_start(); $pid = ($_SESSION['pid']); require "../Connect.php"; $query = "select * from member where pid= '".$pid."'"; $result= mysql_query($query,$connection) or die("Unable to perform query $query".mysql_error()); $row= mysql_fetch_array($result); ?> <?php $limit = 10; $query_count = "SELECT count(*) FROM messages where pid= '".$pid."'"; $result_count = mysql_query($query_count); $totalrows = mysql_num_rows($result_count); if(empty($page)){ // Checks if the $page variable is empty (not set) $page = 1; // If it is empty, we're on page 1 } $limitvalue = $page * $limit - ($limit); $query1 = "select * from messages where pid= '".$pid."' LIMIT $limitvalue, $limit"; $result1= mysql_query($query1,$connection) or die("Unable to perform query $query1".mysql_error()); #$queryer = "SELECT * FROM table messages $limitvalue, $limit"; #$resulter = mysql_query($queryer) or die("Error: " . mysql_error()); if(mysql_num_rows($result1) == 0){ echo("Nothing to Display!"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <!-- Holiday-Friends.Com --> <!-- Built by Business Information Technology Students --> <!-- Representing Bournemouth University England --> <!-- All website built and owned by Adam Dale, Nick Whitmarsh and Daniel Salter --> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Holiday-Friends.Com</title> <style type="text/css" media="all"> @import "../css/loggedinsheet.css"; </style> </head> <body> <div id="page"> <div id="container"> <div id="top"> <div id="logo"><a href="index.html"><img src="../logo.PNG" width="298" height="35" border="0" /></a></div> <div id="top-l"><img src="../f4_1.GIF" /></div> <div id="top-r"><img src="../f4_2.GIF" /></div> <?php include ("s-box.html") ?> </div> <?php include ("menu.html") ?> <div id="interaction"> <?php include ("box.html") ?> </div> <div id="advert">advert</div> <div id="advert-2">advert 2</div> <!-- Message Centre --> <div id="mc-holder"> <div id="flash-holder1"> flash animation</div> <div id ="mc1"> <a href ="mc-inbox-main.php"><b>Inbox</b></a> | <a href ="mc-compose.php">Compose</a> | <a href="mc-sent.php">Sent</a> | </div> <table width="487" border="0" align="center"> <tr style="background-color:#F7F7F7"> <td><table width="476" border="0" align="center"> <tr style="background-color:#EBEBEB"> <td width="40">Status</td> <td width="30">Delete</td> <td width="87">From</td> <td width="211">Subject</td> <td width="83">Date</td> </tr> <?php while ($row1= mysql_fetch_array($result1)) {?> <tr style="background-color:#FFFFFF"> <?php $from = $row1['sender']; $query3 = "select * from member where pid= '".$from."'"; $result3= mysql_query($query3,$connection) or die("Unable to perform query $query3".mysql_error()); $row3= mysql_fetch_array($result3); $fname = $row3['fname']; $sname = $row3['sname']; $fname=substr($fname, 0, 1); $mid = $row1['mid']; $_SESSION['time'] = $row1['time']; $datetime = $row1["time"]; $year = substr( $datetime, 0, 4 ); $mon = substr( $datetime, 4, 2 ); $day = substr( $datetime, 6, 2 ); $hour = substr( $datetime, 8, 2); $min = substr( $datetime, 10, 2 ); $sec = substr( $datetime, 12, 2 ); $orgdate = date("j M, Y ", mktime($hour, $min, $sec, $mon, $day, $year ) ); ?> <?php $status = $row1['status']; if($status == 0) { $FILENAME = "inbox-up.gif"; } else if($status == 1) { $FILENAME = "menu_inbox.gif"; } else { $FILENAME = "inbox-up.gif"; } ?> <td><img src="../graphics/<?php echo ($FILENAME)?>" /></td> <td> <input type="checkbox" name="checkbox" value="checkbox" /> </td> <td><?php echo $sname;?>, <?php echo $fname;?></td> <td><a href="mc-inbox-read?MID=<?php echo $mid?>&T=<?php echo $row1['time'];?>"><?php echo $row1['subject'];?></a></td> <td><?php echo $orgdate;?></td> </tr> <?php } ?> </table></td> </tr> </table> <?php if($page != 1){ $pageprev = $page--; echo("<a href=\"mc-inbox-main.php&page=$pageprev\">PREV".$limit."</a> "); }else echo("PREV"." "); $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"mc-inbox-main&page=$i\">$i</a> "); } } if(($totalrows % $limit) != 0){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"mc-inbox-main&page=$i\">$i</a> "); } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo("<a href=\"mc-inbox-main?page=$pagenext\">NEXT".$limit."</a>"); /* Since there are pages remaining, this outputs NEXT in link form. */ }else{ echo("NEXT"); /* If we're on the last page possible, NEXT will NOT be displayed in link form. */ } ?> </div> </div> </div> </div> <?php include ("footer.html") ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/61287-pagination-not-working/ Share on other sites More sharing options...
GingerRobot Posted July 22, 2007 Share Posted July 22, 2007 Do you think you could tell us what you mean when you say its not working? What's not working? What happens? Do you get an error message? Quote Link to comment https://forums.phpfreaks.com/topic/61287-pagination-not-working/#findComment-304948 Share on other sites More sharing options...
nick_whitmarsh Posted July 22, 2007 Author Share Posted July 22, 2007 Basically I know I should have had 14 results. I have set a limit of 10 of these to show, then the other 4 show on the next page. However all it shows is PREV 1 NEXT. It does not give an option to click and go onto another page to display the results. The whole pricnicple of pagination is not working. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/61287-pagination-not-working/#findComment-304953 Share on other sites More sharing options...
GingerRobot Posted July 22, 2007 Share Posted July 22, 2007 So, just to be clear, the text is being displayed for the pages, but they are not links? Also, you'll need to add this line: $page = $_GET['page']; To the top of your file. Quote Link to comment https://forums.phpfreaks.com/topic/61287-pagination-not-working/#findComment-304957 Share on other sites More sharing options...
nick_whitmarsh Posted July 22, 2007 Author Share Posted July 22, 2007 Thats correct they are not links. It also does not develop the number for a new page. I just shows page one and I know that there hsould be two pages. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/61287-pagination-not-working/#findComment-304961 Share on other sites More sharing options...
GingerRobot Posted July 23, 2007 Share Posted July 23, 2007 Are you 100% sure that there are supposed to be two pages being shown? Can you echo out $totalrows after setting it? $totalrows = mysql_num_rows($result_count); echo 'Total rows: '.$totalsrows.'<br />'; The reason why i wanted to make sure is that this would be the correct behaviour of the pagination if there was only one page, and i cant spot anything obviously wrong with the code at the moment. Quote Link to comment https://forums.phpfreaks.com/topic/61287-pagination-not-working/#findComment-305234 Share on other sites More sharing options...
sasa Posted July 23, 2007 Share Posted July 23, 2007 $pageprev = $page--; must be $pageprev = $page-1; and $pagenext = $page++; must be $pagenext = $page+1; BTW can somebody correct this tutorial Quote Link to comment https://forums.phpfreaks.com/topic/61287-pagination-not-working/#findComment-305239 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.