Jump to content

Recommended Posts

Hi Guys,

 

i have constructed a forum (very basic) i have 2 main categories , 1 has id 1 and the other 2.

 

once a topic is posted within these categories a 1 or a 2 is stored into `topic_id` which is in `forum_topics`

 

so if i post in category 1, a 1 is stored into `forum_topics` as a way of tracking the different categories that are added later, my problem is when i put my pagination in for the sections, (it displays the correct number of links for each section) but still shows me all the posts, the links are right but it still displays the posts on the 1 page

 

can anyone see any errors in my coding as to why that is:

 

     // logged in users id...////////////////////////////////////////////////////////////
     $query2 = "SELECT * FROM `membership` WHERE`username`='$member'";
     $result2 = mysql_query($query2) or die (mysql_error());
     $rows = mysql_fetch_array($result2) or die (mysql_error());     
     // members id...////////////////////////////////////////////////////////////////////
     $member_id = $rows['id'];
     // first get the id...//////////////////////////////////////////////////////////////
     $id = $_GET['id'];
          
     $query = "SELECT * FROM `forum_sections` WHERE `id`='$id'";
     $result = mysql_query($query) or die (mysql_error());
     $row = mysql_fetch_array($result) or die (mysql_error());     
     $subject = $row['subject'];
     
        ## Pagination start #############################################################
        echo "<center>";
	// If current page number, use it 
	// if not, set one! 

	if(!isset($_GET['page'])){ 
		$page = 1; 
	} else { 
		$page = $_GET['page']; 
	} 

	// Define the number of results per page 
	$max_results = 1; 		

	// Figure out the limit for the query based 
	// on the current page number. 
	$from = (($page * $max_results) - $max_results);  

	// Perform MySQL query on only the current page number's results 

	$sql = mysql_query("SELECT * FROM `forum_topics` LIMIT $from, $max_results"); 

        ## Pagination start #############################################################
     
     $query2 = "SELECT * FROM `forum_topics` WHERE `topic_id`='$id' ORDER BY `topic_name` DESC";
     $result2 = mysql_query($query2) or die (mysql_error());
          
     echo "<br /><b>Viewing Forum Section -> $subject<br /><br />";
     echo '<table width="600" border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" />
           <tr>
           <th bgcolor="#004E98" /><font color="#ffffff">Topic</font></th><th bgcolor="#004E98" /><font color="#ffffff">Replies</font></th><th bgcolor="#004E98" /><font color="#ffffff">Views</font></th><th bgcolor="#004E98" /><font color="#ffffff">Author</font></th>
           </tr>
           <tr>';
           
     // while loop for the topics.../////////////////////////////////////////////////////
     while ($rows = mysql_fetch_array($result2)) {     
     // variables.../////////////////////////////////////////////////////////////////////     
     $topic_id = $rows['id'];
     $real_topic_id = $rows['topic_id'];
     $topic_name = $rows['topic_name'];
     $date_added = $rows['date_added'];
     $user_id = $rows['user_id'];
     $views = $rows['views'];
     $replies = $rows['replies'];
     
     $query3 = "SELECT * FROM `membership` WHERE `id`='$user_id'";
     $result3 = mysql_query($query3) or die (mysql_error());
     $row_postername = mysql_fetch_array($result3) or die (mysql_error());
     
     // how many replies...//////////////////////////////////////////////////////////////
     $replies = mysql_num_rows($result2);
     
     $poster_id = $row_postername['id'];
     $poster_name = $row_postername['username'];
     
     echo "<td><a href=\"read_forum.php?id=$topic_id\">$topic_name</a></td><td>$replies</td><td>$views</td><td><a href=\"user_details.php?id=$poster_id\"/>$poster_name</a></td></tr>";
     
     }
                      
     echo '</table><br />';
     
        ## Pagination end ###############################################################

         // Figure out the total number of results in DB:...///////////////////////////// 
	$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM `forum_topics` WHERE `topic_id`='$real_topic_id'"),0); 

	// Figure out the total number of pages. Always round up using ceil().../////////
	$total_pages = ceil($total_results / $max_results); 

	// Build Previous Link...//////////////////////////////////////////////////////// 
	if($page > 1){ 
		$prev = ($page - 1); 
		echo " <a href=\"".$_SERVER['PHP_SELF']."?id=$id&page=$prev\"><<< </a> "; 
	} 

	for($i = 1; $i <= $total_pages; $i++){ 
		if(($page) == $i){ 
			echo "[<b>$i</b>] "; 
			} else { 
				echo "<a href=\"".$_SERVER['PHP_SELF']."?id=$id&page=$i\">$i</a> "; 
		} 
	} 

	// Build Next Link...////////////////////////////////////////////////////////////
	if($page < $total_pages){ 
		$next = ($page + 1); 
		echo "<a href=\"".$_SERVER['PHP_SELF']."?id=$id&page=$next\"> >>></a>"; 
	} 
	echo "<br /><br />"; 

        ## Pagination end ###############################################################
        
     echo '<form action="add_forum_topic.php?id='.$id.'" method="POST"/><input type="submit" name="submit" value="Add New Topic" /></form>';
     echo '<input type="hidden" value="'.$member_id.'" />';

 

cheers guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/52197-solved-counting-a-specific-id-to-display/
Share on other sites

please use code tags

 

but

$sql = mysql_query("SELECT * FROM `forum_topics` LIMIT $from, $max_results"); 

isn't being used

 

so surely you should do this

 

        ## Pagination start #############################################################
     
     $query2 = "SELECT * FROM `forum_topics` WHERE `topic_id`='$id' ORDER BY `topic_name` DESC  LIMIT $from, $max_results";
     $result2 = mysql_query($query2) or die (mysql_error());

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.