...

View Full Version : Pagination



rscott
06-18-2012, 06:19 PM
I have gotten my pagination working but can someone offer a suggestion how I can modify my code so that only the news entry area is affected? I don't want the main section to keep refreshing if the user has gone to other pages. Thanks for your time.

Can be seen in action here in studio news area:http://www.rscottsculpture.com/index.php

And the code for the news.inc where paging is going on:



<?php
//make connection to database
$con = mysql_connect("localhost", "thameu_visitor", "visitor159") or die('Sorry, could not connect to database server');
mysql_select_db("thameu_sculpture", $con) or die('Sorry, could not connect to database');

$query = "SELECT count(title) from news";
$result = mysql_query($query);
$row=mysql_fetch_array($result);

//if there are no articles say so
if ($row[0] == 0)

{
echo "No news posted yet.&nbsp;&nbsp;\n";

//but if there are, get total records
} else

{
$totrecords = $row[0];

//set the page as 1
if (!isset($_GET['page']))
$thispage = 1;
else
$thispage = $_GET['page'];

//how many articles to post per page
$recordsperpage = 3;
$offset = ($thispage - 1) * $recordsperpage;
$totpages = ceil($totrecords / $recordsperpage);

$query = "SELECT title,date,article from news order by date desc limit $offset,$recordsperpage";

$result = mysql_query($query) or die('Could not retrieve any news: ' . mysql_error());


while($row = mysql_fetch_array($result, MYSQL_ASSOC))

//display the articles
{
$date = $row['date'];
$title = $row['title'];
$article = $row['article'];

echo"<div style=\"width:95%;-webkit-border-radius: 20px;-moz-border-radius: 20px;border-radius: 20px;border:2px solid '#'802828;background:rgba(74,120,58,0.5);text-align:center;padding-left:4px;padding-right:4px;\">";
echo "<br>$date - $title<p>$article<br><br>";
echo"</div>";
}

if ($thispage > 1)

{
$page = $thispage - 1;
$prevpage = "<a href=\"index.php?newscontent=news.inc&page=$page\">Previous</a>";

} else
{
$prevpage = "";
}
$bar = '';

if ($totpages > 1)

{

for($page = 1; $page <= $totpages; $page++)

{

if ($page == $thispage)
{
$bar .= " $page ";
} else
{
$bar .= " <a href=\"index.php?newscontent=news.inc&page=$page\">$page</a> ";
}
}
}

if ($thispage < $totpages)
{
$page = $thispage + 1;
$nextpage = " <a href=\"index.php?newscontent=news.inc&page=$page\">Next</a>";
} else
{
$nextpage = "";
}
echo "Go to: " . $prevpage . $bar . $nextpage;
}
?>
</div>

firepages
06-19-2012, 12:14 AM
an iframe or preferably AJAX so your 1,2, links etc would call a javascript method that rewrites your 'Studio News' content, its really a client side issue , I can move this post to javascript if you want.

rscott
06-19-2012, 12:55 AM
Thank you for your reply, go ahead and move it I'll give the javascript forum a shot.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum