Jump to content

3 records per page, why soo complicated :(


jesushax

Recommended Posts

Hi ive been searching and trying out pagnation scripts for the last hour, and they either dont work or not what i need

 

all i want is to have 3 news items displayed per page

 

can someone show me an easy way here?

 

Thankyou

 

here is my code

 

<?php
include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php');

$sql =  mysql_query("SELECT * From tblNews") or die(mysql_error());

while ($news = mysql_fetch_array($sql)) {
echo '<div style="float:left; width:100%; margin-bottom:10px;">';
echo '<a href="fullstory.asp?id='.$news["NewsID"].'">'.$news["NewsTitle"]."</a>";
echo "  -  <i>";
echo $news["NewsDateAdded"];
echo "</i></div>";
echo '<div style="width:70%; margin-right:10px; float:left;">';
echo str_replace("\n", "<br />",$news["NewsShort"]);
echo "</div>";

if (empty($news["NewsImage1"])) {
echo ""; 
} else {
echo '<div style="width:200px; float:left;">';
echo '<img style="border:1px dashed #666666;" src="/news/uploads/'.$news["NewsImage1"].' " alt=" '.$news["NewsImage1"].' " />';
echo '</div>';
}

if (empty($news["NewsAttachment"])) {
echo ""; }
else {
echo "<div style=\"float:left; width:100%;\">Attachment";
echo '<a href="/news/uploads/';
echo $news ["NewsAttachment"].'" onclick="target=\'blank\';">';
echo $news ["NewsAttachment"]."</a></div>";
} 
echo '<div style="padding-bottom:10px; border-bottom:1px dashed #666666; float:left; width:100%; text-align:center; margin-bottom:30px;"><a href="/news/full_news.asp?id='.$news["NewsID"].'">'."View the full story"."</a></div>"; 
}

include($_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php');
?>

Link to comment
Share on other sites

<?php
if(!isset($_GET['page'])){
$page = 1;
}else{
$page = $_GET['page'];
}
$limit = 3;
$limitvalue = $page * $limit - ($limit); 
$query_count = "SELECT SQL_CALC_FOUND_ROWS
  title,
  content,
  URL,
  id
FROM $searchType
  WHERE
    MATCH(URL,title,content) AGAINST ('$searchQuery' IN BOOLEAN MODE) AND
content IS NOT NULL
LIMIT $limitvalue, $limit";

$sql = mysql_query($query_count)or die(mysql_error()); 
$result_count = mysql_query("SELECT FOUND_ROWS()")or die(mysql_error());
$total = mysql_fetch_array($result_count);
$totalrows = $total[0];





//Start Page Numbering		

	$numofpages = $totalrows / $limit;
	if($numofpages > 100){
		$numofpages = 100;
	}
	if($numofpages > 1){		
		echo '<p> </p>';
		echo '<div style="text-align:center">';
		if($page != 1){ 
			$pageprev = $page-1;
			echo '<a class="pageNation" href="'.$PHP_SELF.'?q='.htmlentities($_GET['q']).$addToStr.'&page='.$pageprev.'">Prev</a>'; 
		}else{
			echo '<span class="NPNone">Prev</span>';
		}

		if($page > 5){
			echo ' <a class="pageNation" href="'.$PHP_SELF.'?q='.htmlentities($_GET['q']).$addToStr.'&page=1">1</a> ... ';
		}




		for($i = ($page - 5); $i < ($page + 6); $i++){
			// only make a link if the prev/next is a valid page number 
			if (($i >= 1) && ($i < $numofpages)) {
				if ($page == $i){ 
					echo ' <span class="pageNone">'.$i.'</span> ';
				}else{ 
					echo' <a class="pageNation" href="'.$PHP_SELF.'?q='.htmlentities($_GET['q']).$addToStr.'&page='.$i;
					if(isset($_GET['view']) && $page != $i){
						echo '&view='.$_GET['view'];
					}
					echo'">'.$i.'</a> ';
				} // end if 
			}
		} // end for			


		$last = ceil($numofpages);
		if(($page + 6) < $numofpages){
			echo ' ... <a class="pageNation" href="'.$PHP_SELF.'?q='.htmlentities($_GET['q']).$addToStr.'&page='.$last.'">'.$last.'</a> ';
		}
		else if(($page + 5) >= $numofpages && ($page != $last)){
			echo ' <a class="pageNation" href="'.$PHP_SELF.'?q='.htmlentities($_GET['q']).$addToStr.'&page='.$last.'">'.$last.'</a> ';
		}
		else{
			echo ' <span class="pageNone">'.$last.'</span> ';
		}










		if(($totalrows - ($limit * $page)) > 0){
			$pagenext = $page+1;
			echo '<a class="pageNation" href="'.$PHP_SELF.'?q='.$_GET['q'].$addToStr.'&page='.$pagenext.'">Next</a>'; 
		}else{
			echo ' <span class="NPNone">Next</span> '; 
		}
		mysql_free_result($sql);
	}
?>

Link to comment
Share on other sites

heres what i have now,

 

where am i supposed to put my code to display my records?

 

utterly confused by php paging im am...  ???

 

<?php

include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php');

if(!isset($_GET['page'])){
$page = 1;
}else{
$page = $_GET['page'];
}
$limit = 3;
$limitvalue = $page * $limit - ($limit); 
$query_count = "SELECT SQL_CALC_FOUND_ROWS * From tblNews LIMIT $limitvalue, $limit";
$sql =  mysql_query($query_count) or die(mysql_error());

$result_count = mysql_query("SELECT FOUND_ROWS()")or die(mysql_error());
$total = mysql_fetch_array($result_count);
$totalrows = $total[0];

//Start Page Numbering		

	$numofpages = $totalrows / $limit;
	if($numofpages > 100){
		$numofpages = 100;
	}
	if($numofpages > 1){		
		echo '<p> </p>';
		echo '<div style="text-align:center">';
		if($page != 1){ 
			$pageprev = $page-1;
			echo '<a class="pageNation" href="'.$PHP_SELF.'?q='.htmlentities($_GET['q']).$addToStr.'&page='.$pageprev.'">Prev</a>'; 
		}else{
			echo '<span class="NPNone">Prev</span>';
		}

		if($page > 5){
			echo ' <a class="pageNation" href="'.$PHP_SELF.'?q='.htmlentities($_GET['q']).$addToStr.'&page=1">1</a> ... ';
		}

		for($i = ($page - 5); $i < ($page + 6); $i++){
			// only make a link if the prev/next is a valid page number 
			if (($i >= 1) && ($i < $numofpages)) {
				if ($page == $i){ 
					echo ' <span class="pageNone">'.$i.'</span> ';
				}else{ 
					echo' <a class="pageNation" href="'.$PHP_SELF.'?q='.htmlentities($_GET['q']).$addToStr.'&page='.$i;
					if(isset($_GET['view']) && $page != $i){
						echo '&view='.$_GET['view'];
					}
					echo'">'.$i.'</a> ';
				} // end if 
			}
		} // end for			


		$last = ceil($numofpages);
		if(($page + 6) < $numofpages){
			echo ' ... <a class="pageNation" href="'.$PHP_SELF.'?q='.htmlentities($_GET['q']).$addToStr.'&page='.$last.'">'.$last.'</a> ';
		}
		else if(($page + 5) >= $numofpages && ($page != $last)){
			echo ' <a class="pageNation" href="'.$PHP_SELF.'?q='.htmlentities($_GET['q']).$addToStr.'&page='.$last.'">'.$last.'</a> ';
		}
		else{
			echo ' <span class="pageNone">'.$last.'</span> ';
		}


		if(($totalrows - ($limit * $page)) > 0){
			$pagenext = $page+1;
			echo '<a class="pageNation" href="'.$PHP_SELF.'?q='.$_GET['q'].$addToStr.'&page='.$pagenext.'">Next</a>'; 
		}else{
			echo ' <span class="NPNone">Next</span> '; 
		}
		mysql_free_result($sql);
	}

	include($_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php');
?>

Link to comment
Share on other sites

found one and got it working, very easy very simple

 

<?php
include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php');

$max = 3; //amount of articles per page. change to what to want
$p = @$_GET['p'];
if(empty($p))
{
$p = 1;
}
$limits = ($p - 1) * $max; 

//view all the news articles in rows
$sql = mysql_query("SELECT * FROM tblNews LIMIT ".$limits.",$max") or die(mysql_error());
//the total rows in the table
$totalres = mysql_result(mysql_query("SELECT COUNT(NewsID) AS tot FROM tblNews"),0);	
//the total number of pages (calculated result), math stuff...
$totalpages = ceil($totalres / $max); 

echo "<div style='text-align:center;'>View Page: ";
for($i = 1; $i <= $totalpages; $i++){ 
//this is the pagination link
echo "<a href='short_news.php?p=$i'>$i</a>|";
}
echo "</div>";
while($news = mysql_fetch_array($sql))
{
//replace with your news page
echo '<div style="float:left; width:100%; margin-bottom:10px;">';
echo '<a href="fullstory.asp?id='.$news["NewsID"].'">'.$news["NewsTitle"]."</a>";
echo "  -  <i>";
echo $news["NewsDateAdded"];
echo "</i></div>";
echo '<div style="width:70%; margin-right:10px; float:left;">';
echo str_replace("\n", "<br />",$news["NewsShort"]);
echo "</div>";

if (!empty($news["NewsImage1"])) {

echo '<div style="width:200px; float:left;">';
echo '<img style="border:1px dashed #666666;" src="/news/uploads/'.$news["NewsImage1"].' " alt=" '.$news["NewsImage1"].' " />';
echo '</div>';
}

if (!empty($news["NewsAttachment"])) {
echo "<div style=\"float:left; width:100%;\">Attachment";
echo '<a href="/news/uploads/';
echo $news ["NewsAttachment"].'" onclick="target=\'blank\';">';
echo $news ["NewsAttachment"]."</a></div>";
} 
echo '<div style="padding-bottom:10px; border-bottom:1px dashed #666666; float:left; width:100%; text-align:center; margin-bottom:30px;"><a href="/news/full_news.php?id='.$news["NewsID"].'">'."View the full story"."</a></div>"; 
}
//end replacing
echo "<div style='text-align:center;'>View Page: ";
for($i = 1; $i <= $totalpages; $i++){ 
//this is the pagination link
echo "<a href='short_news.php?p=$i'>$i</a>|";
}
echo "</div>";


include($_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php');

?>

Link to comment
Share on other sites

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.