Hi,
I'm learning making CMS. As you can see, I cannot do everything from scratch. So I request anyone with code in his codebase that works fine on paging or knows practical code to point me. I want to page my articles once are more than let say 10

Cheers :)

Here's a script from this article.

<?php
$pages_left=3;
$pages_middle=4;
$pages_right=2;
 
$total_pages=100;
if (!isset($_GET['page']) && empty($_GET['page'])) {
$currentpage=0;
} else {
$currentpage=$_GET['page'];
}
for ($p=0;$p<=$total_pages;$p++) {
    if ($p<$pages_left || $p>=($total_pages-$pages_right) || ($p>=($currentpage-floor($pages_middle/2)) && $p<=($currentpage+floor($pages_middle/2)))) {
        if ($p==$currentpage) {
        echo ($p>0)?' - ':'';
        echo '<b>'.($p+1).'</b>';
        } else {
        echo ($p>0)?' - ':'';
        echo '<a href="index.php?page='.$p.'"><b>'.($p+1).'</b></a>';
        }
    }
}
?>
commented: Great! +6

Thanks guys!
I will try to implement your good codes.
Not Closed yet, so if anyone wants to say anything ;)

<?php
	require_once("config/connect.php");
	require_once("config/config.php");
	require_once("config/function.php");
	require_once("config/url-function.php");
	require_once("design/sitepanel.php");
	
	$select_total = "select pr_Id from pressrelease where pr_Flag = 1 and pr_Releasedate <= CURDATE() order by pr_Releasedate desc,editor_Choice desc,pr_Approvedate desc";
	$result_total = mysql_query($select_total);
	$Total = mysql_num_rows($result_total);
	$PageData = 10; // rowsperpage
	$TotalPages = ceil($Total/$PageData); // maxpages
	$pageNum = 1;
	$url = '/recent-pr-';
	
	if(isset($_GET['page']) && $_GET['page'] != '')
	{
		$pageNum = $_GET['page'];
	}
	
	if($pageNum > $TotalPages)
	{
		header("HTTP/1.0 404 Not Found");
		exit;
	}
	
	$browser_url = "http://".$HTTP_SERVER_VARS['HTTP_HOST'].$HTTP_SERVER_VARS['REQUEST_URI'];
	if($pageNum == 1)
	{
		$page_url = DOMAIN_NAME;
	}
	else
	{
		$page_url = DOMAIN_NAME.'recent-pr-'.$pageNum.'/';
	}
	if ( NULL != strcmp($browser_url,$page_url))
	{	
		header("HTTP/1.0 301 Moved Permanantly");
		header("Location: ".DOMAIN_NAME);
		exit;
	}
	
	$offset = ($pageNum - 1) * $PageData;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Free Press Release Submission and Online News Distribution<?php echo ($pageNum != 1) ? ' - Page '.$pageNum : '';?></title>
<?php
if($pageNum == 1)
{
?>
<meta name="keywords" content="Online News, PR Submission, Free Press Release Submission, PR Distribution" />
<meta name="description" content="Submit and distribute online news and press releases to our media and RSS channels." />
<?php
}
?>
<link href="/design/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php
	header_before_login();		// header of site
?>

<table width="980" cellpadding="0" cellspacing="0" border="0" align="center">
	<tr>
		<td width="220" valign="top" align="left">

			<?php
			// Left panel of site
			site_navigation();
			industries();
			?>

		</td>
		<td width="10"></td>
		<td width="750" valign="top" align="left">

			<?php
			if($pageNum == 1)
			{
			?>
			<table width="100%" class="top8" border="0" cellspacing="0" cellpadding="0" align="center">
				<tr>
					<td class="top-tl"></td>
					<td class="top-t"></td>
					<td class="top-tr"></td>
				</tr>
				<tr>
					<td class="top-l1"></td>
					<td class="top-center1">
						<table width="100%" cellpadding="0" cellspacing="0" border="0">
							<tr>
								<td valign="bottom"><img src="/images/index-img1.jpg" alt="Welcome Image1" title="Welcome to <?php echo SITE;?>" width="226" height="157" /></td>
								<td valign="top">
									<div class="tophead">Welcome to <?php echo SITE1;?></div>
									  We offer Free Press Release Submission to our users and provide Online News and PR distribution to targeted audience. 
									<br /><Br />
								</td>
							</tr>
						</table>
					</td>
					<td class="top-r1"></td>
				</tr>
				<tr>
					<td class="top-l2"></td>
					<td class="top-center2">
						<table width="100%" cellpadding="0" cellspacing="0" border="0">
							<tr>
								<td valign="top"><img src="/images/index-img2.jpg" alt="Welcome Image2" title="Welcome to <?php echo SITE;?>" width="226" height="44" /></td>
								<td valign="middle" align="right">
									<a href="/login/">Submit Your Press Release >></a>
								</td>
							</tr>
						</table>
					</td>
					<td class="top-r2"></td>
				</tr>
				<tr>
					<td class="top-bl"></td>
					<td class="top-b"></td>
					<td class="top-br"></td>
				</tr>
				<tr>
					<td height="10"></td>
				</tr>
			</table>
			<?php
			}
			?>
			
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<?php
					if($pageNum == 1)
					{
					?>
					<td><h1>Online News Submission and Distribution</h1></td>
					<?php
					}
					else
					{
					?>
					<td class="tophead">Online News Submission and Distribution</td>
					<?php
					}
					?>
				</tr>
			</table>

			<?php
			// fetch press releases 
			$sel_releases = "select pr_Id,pr_Headline,pr_Summary,pr_Company,DATE_FORMAT(pr_Releasedate,'%M %d, %Y') pr_Releasedate1,pr_Url,editor_Choice,pr_Msa,pr_Imported from pressrelease where pr_Flag = 1 
							and pr_Releasedate <= CURDATE() order by pr_Releasedate desc,editor_Choice desc,pr_Approvedate desc limit ".$offset.", ".$PageData;
			$exec_releases = mysql_query($sel_releases);
			if($exec_releases > 0)
			{
				while($data_releases = mysql_fetch_array($exec_releases))
				{
					if($data_releases['editor_Choice'] == 1 || $data_releases['pr_Imported'] != 0)		// if press release is editr's choice
					{
						$cellpadding = 10;
						$heading = 'news-headp';
						$stars = '<p class="fetures-str"><img src="/images/fetures-str.gif" alt="Star" title="Star" /></p><p class="fetures-str"><img src="/images/fetures-str.gif" alt="Star" title="Star" /></p>';
						$choice1 = '<table width="100%" class="curve7" border="0" cellspacing="0" cellpadding="0" align="center">
										<tr>
											<td class="curve-tl"></td>
											<td class="curve-t"></td>
											<td class="curve-tr"></td>
										</tr>
										<tr>
											<td class="curve-l"></td>
											<td class="curve-center">';
						$choice2 = '		</td>
											<td class="curve-r"></td>
										</tr>
										<tr>
											<td class="curve-bl"></td>
											<td class="curve-b"></td>
											<td class="curve-br"></td>
										</tr>
										<tr>
											<td height="10"></td>
										</tr>
									</table>';
					}
					else			// If press release is not editor's choice
					{
						$cellpadding = 8;
						$heading = 'news-headf';
						$stars = '';
						$choice1 = '';
						$choice2 = '';
					}
					
					$prurl = make_pr_url(mystripslashes($data_releases['pr_Msa']),mystripslashes($data_releases['pr_Headline']),$data_releases['pr_Id']);
					
					// Fetch image of press release
					$sel_img = "select image_Path,image_Title,image_Alter from pr_features where fkPrId = ".$data_releases['pr_Id']." and image_Status = 1";
					$res_img = mysql_query($sel_img);
					
					echo $choice1;
					?>
					<table width="100%" cellpadding="0" cellspacing="<?php echo $cellpadding;?>" border="0" class="newstable">
						<tr>
							<td colspan="2" class="<?php echo $heading;?>">
								<?php echo $stars;?>
								<a href="<?php echo $prurl;?>"><?php echo mystripslashes($data_releases['pr_Headline']);?></a>
							</td>
						</tr>
						<tr>
							<td class="news-date">By <?php echo mystripslashes($data_releases['pr_Company']);?> | <?php echo $data_releases['pr_Releasedate1'];?></td>
							<?php
							if(mysql_num_rows($res_img) > 0)
							{
								$data_img = mysql_fetch_array($res_img);
								$arr_resize = resized_image($data_img['image_Path'],100,100);
								?>
								<td width="100" align="center" valign="top" rowspan="2">
									<img src="<?php echo $data_img['image_Path'];?>" width="<?php echo $arr_resize[0];?>" height="<?php echo $arr_resize[1];?>" class="new-img" alt="<?php echo mystripslashes($data_img['image_Alter']);?>" title="<?php echo mystripslashes($data_img['image_Title']);?>" />
								</td>
								<?php
							}
							?>
						</tr>
						<tr>
							<td valign="top">
								<div><?php echo mystripslashes($data_releases['pr_Summary']);?></div>
							</td>
						</tr>
					</table>
					<?php
					echo $choice2;
				}
			}
			?>
			
			<?php
			if($TotalPages > 1)			// When 2 or more pages exist
			{
			?>
			<table width="100%" cellpadding="0" cellspacing="5" border="0" class="pagingtable">
				<tr>
					<td class="paging">
						<?php
						/*for($i=1;$i<=$TotalPages;$i++)
						{
							$url1 = ($i == 1) ? DOMAIN_NAME : $url.$i.'/';
							echo ($pageNum == $i) ? '<span>'.$i.'</span>' : '<a href="'.$url1.'">'.$i.'</a>';
						}*/
						$page_no = 4;
						if($pageNum>$page_no)
						{
							$first = $pageNum-$page_no;
						}
						else
						{
							$first = 1;
						}
						if($pageNum!=1)
						{
							$first1 = $pageNum-1;
							$url_prev = ($first1 == 1) ? DOMAIN_NAME : $url.$first1.'/';
							echo '<a href="'.$url_prev.'">'.Prev.'</a>';
						}
						if($pageNum<$TotalPages-$page_no)
						{
							$last = $pageNum+$page_no;
						}
						else
						{
							$last = $TotalPages;
						}
						$count=1;
						for($count=$first;$count<=$last;$count++)
						{
							$url1 = ($count == 1) ? DOMAIN_NAME : $url.$count.'/';
							echo ($pageNum == $count) ? '<span>'.$count.'</span>' : '<a href="'.$url1.'">'.$count.'</a>';
						}
						$last1 = $pageNum+1;
						$url_last = $url.$last1.'/';
						if($pageNum<$TotalPages)
						{
						?>
							<a href="<?php echo $url_last;?>">Next</a>
						<?php
						}
						?>
					</td>
				</tr>
			</table>
			<?php
			}
			?>
			
		</td>
	</tr>
</table>

<?php
	site_footer();
?>
</body>
</html>

Thanks for bringing this to my attention.
I will mark it solved :)

Thanks for bringing this to my attention.
I will mark it solved :)

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.