Hi,

I have a table and i want to list details in list.php with pagging style. 2 record each. I can't do it. Can anyone help me. I have tried some examples but, i couldn't do it.

Please help. Thanks

CREATE TABLE `country` (
  `code` varchar(255) default NULL,
  `rank` int(11) default NULL,
  `name` varchar(255) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `country` VALUES ('IN', '1', 'India');
INSERT INTO `country` VALUES ('CH', '2', 'China');
INSERT INTO `country` VALUES ('AL', '3', 'Algeria');
INSERT INTO `country` VALUES ('NL', '4', 'Netherland');
INSERT INTO `country` VALUES ('AU', '5', 'Austuria');

you mean paging with 2 records in each page?
i also workd on paging, and it worked for me.. but i didn't try 2 records yet in each page..
umm at least 10..

i'll post the code if that's might help.

enim

ei, it works! 2 records in each page.. hehehhe :)

enim

try this..

<?php
	include('connect.php');

	$tbl_name="table_name";	
	$adjacents = 2;
	
	$query = "SELECT COUNT(*) AS NUM...";
	$total_pages = mysql_fetch_array(mysql_query($query));
	$total_pages = $total_pages[num];
	
	$targetpage = $_SERVER['PHP_SELF']; 
	$limit = 2; 		
	$page = $_GET['page'];
	
	if($page) 
	{
		$start = ($page - 1) * $limit; 
	}
	else
	{
		$start = 0;	
	}
	
	$sql = "SELECT . . .LIMIT $start, $limit";
	$result = mysql_query($sql);
	
	if ($page == 0) $page = 1;	
	$prev = $page - 1;	
	$next = $page + 1;	
	$lastpage = ceil($total_pages/$limit);	
	$lpm1 = $lastpage - 1;
	
	$pagination = "";
	if($lastpage > 1)
	{	
		if ($page > 1) 
		{
			$pagination.= "<a href=\"$targetpage?page=$prev\" class=\"link\">« previous</a>&nbsp;&nbsp;";
		}
		else
		{
			$pagination.= "<span class=\"disabled\">« previous</span>";	
		}
		
		if ($lastpage < 7 + ($adjacents * 2))
		{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
				{
					$pagination.= "<span class=\"current\">$counter</span>";
				}
				else
				{
					$pagination.= "<a href=\"$targetpage?page=$counter\" class=\"link\">$counter</a>";					
				}
			}
		}
		elseif($lastpage > 5 + ($adjacents * 2))
		{
			if($page < 1 + ($adjacents * 2))		
			{
				for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
				{
					if ($counter == $page)
					{
						$pagination.= "<span class=\"current\">$counter</span>";
					}
					else
					{
						$pagination.= "<a href=\"$targetpage?page=$counter\" class=\"link\">$counter</a>";					
					}
				}
				$pagination.= "...";
				$pagination.= "<a href=\"$targetpage?page=$lpm1\" class=\"link\">$lpm1</a>";
				$pagination.= "<a href=\"$targetpage?page=$lastpage\" class=\"link\">$lastpage</a>";		
			}
			elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
			{
				$pagination.= "<a href=\"$targetpage?page=1\" class=\"link\">1</a>";
				$pagination.= "<a href=\"$targetpage?page=2\" class=\"link\">2</a>";
				$pagination.= "...";
				
				for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
				{
					if ($counter == $page)
					{
						$pagination.= "<span class=\"current\">$counter</span>";
					}
					else
					{
						$pagination.= "<a href=\"$targetpage?page=$counter\" class=\"link\">$counter</a>";					
					}
				}
				$pagination.= "...";
				$pagination.= "<a href=\"$targetpage?page=$lpm1\" class=\"link\">$lpm1</a>";
				$pagination.= "<a href=\"$targetpage?page=$lastpage\" class=\"link\">$lastpage</a>";		
			}
			else
			{
				$pagination.= "<a href=\"$targetpage?page=1\" class=\"link\">1</a>";
				$pagination.= "<a href=\"$targetpage?page=2\" class=\"link\">2</a>";
				$pagination.= "...";
				
				for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $page)
					{
						$pagination.= "<span class=\"current\">$counter</span>";
					}
					else
					{
						$pagination.= "<a href=\"$targetpage?page=$counter\" class=\"link\">$counter</a>";					
					}
				}
			}
		}
		
		if ($page < $counter - 1) 
		{
			$pagination.= "&nbsp;&nbsp;<a href=\"$targetpage?page=$next\" class=\"link\">next »</a>";
		}
		else
		{
			$pagination.= "<span class=\"disabled\">next »</span>";
		}
	}
?>
<tr>
	<td colspan="2" align="center" style="font-size:10px; text-decoration:underline;">
		Page <?=$page?> of <?=$lastpage?>
	</td>
</tr>
<tr>
	<td colspan="2" height="5">
	</td>
</tr>
<tr>
	<td colspan="2" align="center">
		<?=$pagination?>
	</td>
</tr>
<?php
	while($row = mysql_fetch_array($result))
	{
		data
	}
?>

I'll try this when i get home. thanks enim

Hi,

I couldn't do adjustment therefore, i can make it work.

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.