Hi all..

I'm trying to do a pagination using simple php script...

I set the maximum post to be displayed to be 5..

but my problem is, each post that being displayed,has skipped 1 post before it..
For example,let say that i got 5 post in total,instead of displaying post 1,2,3,4 and 5,
my page just display the post of 1,3 and 5 only(skip 1 post).

This is my real post database :

and this is what being displayed on my website page :

and this is my php code for the post :

<?php

    //max displayed per page
	$per_page = 5;
	
	//get started variable
	$start = $_GET['start'];
	
	//count records
	$record_count = mysql_num_rows(mysql_query("SELECT * FROM blogpost"));
	
	//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 blogpost ORDER BY id DESC LIMIT $start,$per_page");
		
		while($row = mysql_fetch_assoc($get))
			{
				//get data
				$r=mysql_fetch_assoc($get);
				$name=$r["name"];
				$comment=$r["comment"];
			
				echo "<div id='blogcontainer'>"."<img src='images/keyboard.png' height='100' width='100' />"."<div id='blogtitle'>".$row["title"]."</div>".
			"<br/>"."<div id='blogpost'>"."<div id='mainpost'>".$row["blogpost"]."</div>".""."<div id='date'>".$row["dp_datetime"]."</div>"."<br/>".
			"<a href='#' class='commenttoggle'>comment</a>".
			"<div class='togglebox'>".
			"<div class='commentbox'>".
			"<form method='POST' action='create_comment.php'>".
			"<input type='text' id='name' name='name' size='30'>Name<br/>".
			"<input type='text' id='email' name='email' size='30'>Email<br/>".
			"<input type='text' id='website' name='website' size='30'>Website <br/>".
			"<textarea rows='1' id='commentbox' name='comment' cols='40'></textarea><br/>".
			"<input type='submit' value='comment' id='commentboxsubmit'>".
			"</form>".
			"</div>".
			"</div>".	 
				"</div>"."</div>";
		 }
				
   
		//setup prev and next variables
		$prev = $start - $per_page;
		$next = $start + $per_page;
		
		//show prev button
		echo "<a href='index.php?start=$prev'>Prev</a>";
		
		//show next button
		echo "<a href='index.php?start=$next'>Next</a>";
		
		?>

So, i guess thats all the information that are needed..I hope that somebody could help me out coz i've been spending hours trying to fix this.

Thank You :)

Recommended Answers

All 2 Replies

Check out line 24.

Oh man....
ThankYou2...
silly mistake i guess,ahah...
Thank You :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.