babydoll Posted August 20, 2006 Share Posted August 20, 2006 hithis my script for pagination it is working partly.am happy for that but, it only displays the 1st page, no links to the second pageso the remaining rows too are not displayed.here is the code, help anybody please include ('connection.php'); $limit = 10; // sets limit of how many results to show per page $query_count = "SELECT count(*) FROM topics"; $result_count = mysql_query($query_count); $totalrows = mysql_num_rows($result_count); // a count of all the total rows in the table//Checks if the $page variable is empty (not set)// If it is empty, then we are on page 1 if(empty($page)){ $page = 1; } $limitvalue = $page * $limit - ($limit); // data start check ie for each page which row is to satr from //database query to select items for diaplay $query = "SELECT * FROM topics order by post_timestamp desc LIMIT $limitvalue, $limit"; $result = mysql_query($query) or die("Error: " . mysql_error()); if(mysql_num_rows($result) == 0){ echo("Nothing to Display!"); // a msessage for when table is empty } //data display echo "<table border=\"1\" cellpadding=\"2\" align=\"centre\">"; echo "<tr><th>Article Starter</th>"; echo "<th>Article Content</th>"; echo "<th>Module</th>"; echo "<th> Last Post By </th>"; echo "<th>Role</th>"; echo "<th>Date</th>"; while($row = mysql_fetch_array($result)){ echo "<tr>"; echo "<td><a href='reply_form2.php?topic=".$row['topic_title']."'>". $row['topic_title']."</a></td>"; echo "<td>". $row['topic_details']."</td>"; echo "<td>". $row['mod_id']."</td>"; echo "<td>". $row['topic_creator']."</td>"; echo "<td>".$row['role']."</td>"; echo "<td>" .$row['post_timestamp']."</td>"; echo "</tr>"; } echo "</table>"; //setting up the links on the page numbers if($page != 1){ $pageprev = $page--; echo("<a href=\"new_paging.php?page=$pageprev\"> PREV </a> "); } $numofpages = $totalrows / $limit; // We divide our total amount of rows (for example 102) by the limit (25). //This will yield items per page also number of pages, if we have extra rows remaining for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"new_paging.php?page=$i\">$i</a> "); } }// here handles the surplus rows if(($totalrows % $limit) != 0){ if($i == $page){ echo($i." "); } else{ echo("<a href=\"new_paging.php?page=$i\">$i</a> "); } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo("<a href=\"new_paging.php?page=$pagenext\"> NEXT </a>"); } } mysql_free_result($result); how does one paste php code in this forum because it makes it easier to read the code.thanks Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 20, 2006 Share Posted August 20, 2006 how does one paste php code in this forum because it makes it easier to read the code.You can't You can use the codebox or code as you did, there is no phpbox. There is for only code, codebox, sql, quote and html Link to comment Share on other sites More sharing options...
babydoll Posted August 20, 2006 Author Share Posted August 20, 2006 thanx,i will bear that in mind: any help with the pagination please? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 21, 2006 Share Posted August 21, 2006 Here is your problem: //setting up the links on the page numbers if($page != 1){ $pageprev = $page--;... if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; $page-- is the same thing as saying $page = $page - 1;So your line up there is the same as doing this:$pageprev = $page = $page - 1;You subtract one from $page, store that back into $page, and then store that into $pageprev. This puts the right value in $pageprev, but the problem is that for the rest of the page, the value of $page is smaller than it should be. Try something like this: //setting up the links on the page numbers if($page != 1){ $pageprev = $page - 1;... if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page + 1; Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 22, 2006 Share Posted August 22, 2006 Whaha, I should have know that actually, I didn't noticed Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now