Jump to content

Pagination problem driving me insane


cormac

Recommended Posts

Hi,

 

I've been trying to solve this problem myself for hours but I've had no luck whatsoever, the problem is I don't know PHP, the page I have is hacked together from a few different scripts and seems to be 90% functional but when I click the 'next' and 'previous' links nothing happens. So I'm lost and would really appreciate some help!

 

There is a demo of the page at http://d366804.u40.hosting.digiweb.ie/test/index-old1.php

 

The code is as follows:

 

<?php
require_once('simplepie.inc');

// Set your own configuration options as you see fit.
$feed = new SimplePie();
$feed->set_feed_url(array(
'http://www.independent.ie/business/rss',
'http://www.irishtimes.com/feeds/rss/breaking/business.rss',
'http://www.irishexaminer.com/rss/irishexaminer_business_rss.aspx'
));

$success = $feed->init();
$feed->handle_content_type();

$total_articles = 3;

for ($x = 0; $x < $feed->get_item_quantity($total_articles); $x++)
{
	$first_items[] = $feed->get_item($x);
}// Set our paging values
$start = (isset($_GET['start']) && !empty($_GET['start'])) ? $_GET['start'] : 0; // Where do we start?
$length = (isset($_GET['length']) && !empty($_GET['length'])) ? $_GET['length'] : 3; // How many per page?
$max = $feed->get_item_quantity(); // Where do we end?

?>

<!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=UTF-8" />
<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>

<title>very annoying</title>

<link rel="stylesheet" type="text/css" href="style.css" />

<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

	$('.headline:eq(0)').click(function() {
		$("#mask").animate({
			left: "-320px"
		});
	});

	$('.headline:eq(1)').click(function() {
		$("#mask").animate({
			left: "-640px"
		});
	});

	$('.headline:eq(2)').click(function() {
		$("#mask").animate({
			left: "-960px"
		});
	});


$('.back').click(function() {
$("#mask").animate({
	left: "0px"
});
$('html, body').animate({scrollTop:0}, 'slow'); 
});

$('#home').click(function() {
$("#mask").animate({
	left: "0px"
});
$('html, body').animate({scrollTop:0}, 'slow'); 
});

});
</script>
</head>

<body>
<?php
// If we have an error, display it.
if ($feed->error())
{
	echo '<div class="sp_errors">' . "\r\n";
	echo '<p>' . htmlspecialchars($feed->error()) . "</p>\r\n";
	echo '</div>' . "\r\n";
}
?>

<?php if ($success): ?>


<div id="page-wrap">

	<h1 id="home"><?php echo $feed->get_title(); ?></h1>

	<div id="slider">

		<div id="mask">

			<div id="mainMenu">
				<?php
					foreach ($first_items as $item)
					{
						echo '<div class="headline"><h2>' . $item->get_title() . '</h2><p style="margin: 0;">' . $item->get_date('j M Y') . '</p></div><img src="images/bottom.png" alt="" style="margin: 0 0 10px 5px;" />';
					}
				?>
			</div>

			<?php
				foreach ($first_items as $item)
				{
					echo '<div class="article-text"><h1><a href="' . $item->get_permalink() .'">' . $item->get_title() . '</a></h1><p>' . $item->get_date('j M Y') . '</p><p>' . $item->get_content() . '</p><a class="back"><img src="images/backbutton.png" alt="Back" /></a></div>';
				}
			?>
</div>		<?php endif; ?>

<?php
// Let's do our paging controls
$next = (int) $start + (int) $length;
$prev = (int) $start - (int) $length;

// Create the NEXT link
$nextlink = '<a href="?start=' . $next . '&length=' . $length . '">Next »</a>';
if ($next > $max)
{
	$nextlink = 'Next »';
}

// Create the PREVIOUS link
$prevlink = '<a href="?start=' . $prev . '&length=' . $length . '">« Previous</a>';
if ($prev < 0 && (int) $start > 0)
{
	$prevlink = '<a href="?start=0&length=' . $length . '">« Previous</a>';
}
else if ($prev < 0)
{
	$prevlink = '« Previous';
}

// Normalize the numbering for humans
$begin = (int) $start + 1;
$end = ($next > $max) ? $max : $next;
?>

<p>Showing <?php echo $begin; ?>–<?php echo $end; ?> out of <?php echo $max; ?> | <?php echo $prevlink; ?> | <?php echo $nextlink; ?> |
	</div>

</div></p>

</body>

</html>

 

Thanks in advance for any help you may give.

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.