supanoob Posted March 26, 2007 Share Posted March 26, 2007 ok so i have the following code and it all seems to work the only problem is it will only find one result, now to test i set the limit at 1 and inserted 3 fields manually it will echo one result but wont give me the option to get onto another 2 pages i echoed the total rows and it is only counting 1 any idea why? <?php if ($_GET['step'] == 'view_board') { $limit = 1; // Sets how many results shown per page $board_id=$_GET['board_id']; $query_count = "SELECT count(*) FROM tord_forums where posted_in='$board_id'"; // Sets what we want to pull from the database // count(*) is better for large databases (thanks Greg!) echo "$query_count<br>"; $result_count = mysql_query($query_count); // Pulls what we want from the database echo "$result_count<br>"; $totalrows = mysql_num_rows($result_count); // This counts the number of users echo "$totalrows<br>"; echo "<p align=\"center\">Forums >> Announcements<br>"; echo "</p> <table border=\"0\" width=\"100%\" id=\"table1\"> <tr> <td width=\"50%\" align=\"center\" bgcolor=\"#838383\">Topic Subject</td> <td width=\"20%\" align=\"center\" bgcolor=\"#838383\">Started By</td> <td width=\"10%\" align=\"center\" bgcolor=\"#838383\">Views</td> <td width=\"10%\" align=\"center\" bgcolor=\"#838383\">Replies</td> <td width=\"20%\" align=\"center\" bgcolor=\"#838383\">Options</td> </tr>"; 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); // Ex: (2 * 25) - 25 = 25 <- data starts at 25 $board_id=$_GET['board_id']; $query = "SELECT post_id, post_topic, post_views, post_replies, posted_by, sticky, deleted, reply_to, post_type FROM tord_forums where posted_in='$board_id' and deleted='no' and post_type='topic' LIMIT $limitvalue, $limit"; $result = mysql_query($query) or die("Error: " . mysql_error()); // Selects all the data from table. // mysql_error() will print an error if one occurs. /* Tip: The MySQL LIMIT value syntax is as follows: LIMIT $row_to_start_at, $how_many_rows_to_return */ while($row = mysql_fetch_array($result)){ $post_id=($row['post_id']); $post_topic=($row['post_topic']); $post_replies=($row['post_replies']); $posted_by=($row['posted_by']); $sticky=($row['sticky']); $deleted=($row['deleted']); $reply_to=($row['reply_to']); $post_type=($row['post_type']); echo "<tr> <td bgcolor=\"#A7A7A7\" width=\"50%\"> $post_topic</td> <td width=\"20%\" align=\"center\" bgcolor=\"#A7A7A7\">$posted_by_name</td> <td width=\"10%\" align=\"center\" bgcolor=\"#A7A7A7\">$post_views</td> <td width=\"10%\" align=\"center\" bgcolor=\"#A7A7A7\">$post_replies</td> <td width=\"20%\" align=\"center\" bgcolor=\"#A7A7A7\">[d][s][us]</td> </tr>"; } echo"</table>"; if($page != 1){ $pageprev = $page--; echo("[<a href=\"forum.php?step=view_board&board_id=1&page=$pageprev\">Previous</a>|"); }else{ echo("[Previous|"); } $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo("$i|"); }else{ echo("<a href=\"forum.php?step=view_board&board_id=1?page=$i\">$i</a>|"); } } if(($totalrows % $limit) != 0){ if($i == $page){ echo("$i|"); }else{ echo("<a href=\"forum.php?step=view_board&board_id=1?page=$i\">$i</a>|"); } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo("<a href=\"forum.php?step=view_board&board_id=1?page=$pagenext\">Next</a>]"); }else{ echo("Next]"); } mysql_free_result($result); echo "<br><a href=\"forum.php?step=start_topic\">Start Topic</a><br><br> Options Key: [d] = Delete [s] = Sticky [us] = un-sticky"; } ?> Link to comment https://forums.phpfreaks.com/topic/44373-solved-pagination/ Share on other sites More sharing options...
tom100 Posted March 26, 2007 Share Posted March 26, 2007 Your query select count(*) is merging all your results into 1 row. So if you output the total number of outputted rows, it will only say one. I bet if you output the actual result of the query, you'll get 3. Link to comment https://forums.phpfreaks.com/topic/44373-solved-pagination/#findComment-215499 Share on other sites More sharing options...
supanoob Posted March 26, 2007 Author Share Posted March 26, 2007 so how do i change that? Link to comment https://forums.phpfreaks.com/topic/44373-solved-pagination/#findComment-215505 Share on other sites More sharing options...
tom100 Posted March 26, 2007 Share Posted March 26, 2007 You could change the query to say SELECT * FROM instead of SELECT count(*) to return 3 rows, or look at the value of count. Link to comment https://forums.phpfreaks.com/topic/44373-solved-pagination/#findComment-215507 Share on other sites More sharing options...
Leeder Posted March 26, 2007 Share Posted March 26, 2007 And also use more grammar Link to comment https://forums.phpfreaks.com/topic/44373-solved-pagination/#findComment-215509 Share on other sites More sharing options...
supanoob Posted March 26, 2007 Author Share Posted March 26, 2007 well that opened up the page 1-2-3 links but now when i click page 2-3 it changes the url but it keeps the page on 1 that is to say it keeps the Previous and 1 as non links and shows the same results on all the pages :S Link to comment https://forums.phpfreaks.com/topic/44373-solved-pagination/#findComment-215511 Share on other sites More sharing options...
tom100 Posted March 26, 2007 Share Posted March 26, 2007 page has to be initialized if your sending the variable through the url such as: if ((isset($_GET['page']))&&(ctype_digit($_GET['page']))) { $page=$_GET['page']; } Link to comment https://forums.phpfreaks.com/topic/44373-solved-pagination/#findComment-215520 Share on other sites More sharing options...
supanoob Posted March 26, 2007 Author Share Posted March 26, 2007 Thats sorted it thanks for ya help Link to comment https://forums.phpfreaks.com/topic/44373-solved-pagination/#findComment-215544 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.