TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-16-2009, 12:09 AM   #1 (permalink)
The Visitor
 
Join Date: Nov 2009
Posts: 2
Thanks: 0
johnsonsmith1 is on a distinguished road
Default Convert this code into a google like pagination

I have this RSS parsing code and it paginates , but only uses 'next' and 'previous' links instead of how google does it. I want it to read like this: first 1 2 3.... last

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

// Set your own configuration options as you see fit.
$feed = new SimplePie();
$feed->set_feed_url(array(
'http://feeds2.feedburner.com/MishsGlobalEconomicTrendAnalysis',
'http://feeds.feedburner.com/TheBigPicture',
'http://feeds2.feedburner.com/ChartsAndCoffee',
'http://feeds.feedburner.com/typepad/tradeblogs/the_slope_of_hope_with_ti',
));
$success = $feed->init();



// Make sure the page is being served with the right headers.
$feed->handle_content_type();

// 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'] : 5; // How many per page?
$max = $feed->get_item_quantity(); // Where do we end?

// When we end our PHP block, we want to make sure our DOCTYPE is on the top line to make
// sure that the browser snaps into Standards Mode.
?><!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" xml:lang="en-US" lang="en-US">
<head>
<title>SimplePie: Demo</title>

<link rel="stylesheet" href="styles.css" type="text/css" media="screen, projector" />

</head>

<body>
<div id="site">
<?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): ?>
<?php
// get_items() will accept values from above.
foreach($feed->get_items($start, $length) as $item):
$feed = $item->get_feed();
?>

<div class="chunk">

<h4><?php if ($item->get_permalink()) echo '<a href="' . $item->get_permalink() . '">'; echo $item->get_title(true); if ($item->get_permalink()) echo '</a>'; ?></h4>

<p class="footnote">Source: <a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_title(); ?></a> | <?putenv("TZ=US/Pacific"); echo $item->get_date('j M Y | g:i a'); ?></p>

</div>

<?php endforeach; ?>
<?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 &raquo;</a>';
if ($next > $max)
{
$nextlink = 'Next &raquo;';
}

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

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

<p>Showing <?php echo $begin; ?>&ndash;<?php echo $end; ?> out of <?php echo $max; ?> | <?php echo $prevlink; ?> | <?php echo $nextlink; ?> | <a href="<?php echo '?start=' . $start . '&length=5'; ?>">5</a>, <a href="<?php echo '?start=' . $start . '&length=10'; ?>">10</a>, or <a href="<?php echo '?start=' . $start . '&length=20'; ?>">20</a> at a time.</p>
</div>

</body>
</html>
johnsonsmith1 is offline  
Reply With Quote
Old 11-16-2009, 01:31 AM   #2 (permalink)
The Contributor
 
Join Date: Jun 2009
Location: Seattle, WA
Posts: 76
Thanks: 1
rguy84 is on a distinguished road
Default

Have you tried doing any of it on your own?
__________________
Ryan | Blog | Twitter
Send a message via AIM to rguy84 Send a message via MSN to rguy84 Send a message via Yahoo to rguy84 Send a message via Skype™ to rguy84
rguy84 is offline  
Reply With Quote
Old 11-16-2009, 02:30 AM   #3 (permalink)
The Visitor
 
Join Date: Nov 2009
Posts: 2
Thanks: 0
johnsonsmith1 is on a distinguished road
Default

I found this code online and tried adding it to my original code, but nothing changes.
I have spent a couple hours searching for pagination scripts but I cant get any off them to work with my site. I'm not using mysql a database but RSS.

PHP Code:
******  build the pagination links ******/
// range of num links to show
$range 3;

// if not on page 1, don't show back links
if ($currentpage 1) {
   
// show << link to go back to page 1
   
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
   
// get previous page num
   
$prevpage $currentpage 1;
   
// show < link to go back to 1 page
   
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
// end if

// loop to show links to range of pages around current page
for ($x = ($currentpage $range); $x < (($currentpage $range) + 1); $x++) {
   
// if it's a valid page number...
   
if (($x 0) && ($x <= $totalpages)) {
      
// if we're on current page...
      
if ($x == $currentpage) {
         
// 'highlight' it but don't make a link
         
echo " [<b>$x</b>] ";
      
// if not current page...
      
} else {
         
// make it a link
         
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
      } 
// end else
   
// end if
// end for
                 
// if not on last page, show forward and last page links       
if ($currentpage != $totalpages) {
   
// get next page
   
$nextpage $currentpage 1;
    
// echo forward link for next page
   
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
   
// echo forward link for lastpage
   
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
// end if
/****** end build pagination links ******/ 
johnsonsmith1 is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Prettifying Pasted Code on TalkPHP Wildhoney The Lounge 14 Today 05:26 AM
Writing Clean Code Village Idiot Tips & Tricks 8 01-14-2012 05:29 PM
Game: Let's Develop Something Crazy! Wildhoney The Lounge 25 05-23-2009 10:18 PM
Your opinion on Google? Wildhoney The Lounge 20 12-10-2007 04:29 PM


All times are GMT. The time now is 08:52 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design