Pages: [1]   Go Down
Send this topic | Print
Author Topic: [Script] Sort a list of links into multiple pages  (Read 531 times)
Myles Grey
Full-Time Programmer
Super Authority member
******
Offline Offline

Posts: 1863


Programmer's Delight Release - 90%


WWW
« on: July 20, 2008, 02:30:42 PM »

This is a script that sorts a list of links into multiple pages, re-released after the 110mb forums were hacked. You may set what links you want and the links per page (Look for // links and // set the links per page). You may remove the credit link if you want.

Code:
<?php echo '<?xml version="1.0" encoding="UTF-8" ?>'; ?>

<!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><title>Sort pages into links</title></head>
<body>
<h1>Sort pages into links</h1>

<?php
echo "<p>";

// links
$links[] = array('name' => 'Google - 1', 'url' => 'http://www.google.com/');
$links[] = array('name' => 'Yahoo! - 1', 'url' => 'http://www.yahoo.com/');
$links[] = array('name' => 'Live - 1', 'url' => 'http://www.live.com/');
$links[] = array('name' => 'Google - 2', 'url' => 'http://www.google.com/');
$links[] = array('name' => 'Yahoo! - 2', 'url' => 'http://www.yahoo.com/');
$links[] = array('name' => 'Live - 2', 'url' => 'http://www.live.com/');
$links[] = array('name' => 'Google - 3', 'url' => 'http://www.google.com/');
$links[] = array('name' => 'Yahoo! - 3', 'url' => 'http://www.yahoo.com/');
$links[] = array('name' => 'Live - 3', 'url' => 'http://www.live.com/');
$links[] = array('name' => 'Google - 4', 'url' => 'http://www.google.com/');
$links[] = array('name' => 'Yahoo! - 4', 'url' => 'http://www.yahoo.com/');
$links[] = array('name' => 'Live - 4', 'url' => 'http://www.live.com/');
$links[] = array('name' => 'Google - 5', 'url' => 'http://www.google.com/');
$links[] = array('name' => 'Yahoo! - 5', 'url' => 'http://www.yahoo.com/');
$links[] = array('name' => 'Live - 5', 'url' => 'http://www.live.com/');
$links[] = array('name' => 'Google - 6', 'url' => 'http://www.google.com/');
$links[] = array('name' => 'Yahoo! - 6', 'url' => 'http://www.yahoo.com/');
$links[] = array('name' => 'Live - 6', 'url' => 'http://www.live.com/');
$links[] = array('name' => 'Google - 7', 'url' => 'http://www.google.com/');
$links[] = array('name' => 'Yahoo! - 7', 'url' => 'http://www.yahoo.com/');
$links[] = array('name' => 'Live - 7', 'url' => 'http://www.live.com/');
$links[] = array('name' => 'Google - 8', 'url' => 'http://www.google.com/');
$links[] = array('name' => 'Yahoo! - 8', 'url' => 'http://www.yahoo.com/');
$links[] = array('name' => 'Live - 8', 'url' => 'http://www.live.com/');
$links[] = array('name' => 'Google - 9', 'url' => 'http://www.google.com/');
$links[] = array('name' => 'Yahoo! - 9', 'url' => 'http://www.yahoo.com/');
$links[] = array('name' => 'Live - 9', 'url' => 'http://www.live.com/');

// set the links per page
$links_per_page = 10;

// setup page number
if ($_GET["page"] <= 0)
 
$_GET["page"] = 1;

// echo data onto page
$i = ($_GET["page"] - 1) * $links_per_page;
$end = $i + $links_per_page;
while (
$i < min(count($links),$end)) {
 echo
'<a href="' . $links[$i]["url"] . '">' . $links[$i]["name"] . '</a><br />';
 
$i += 1;
}

// display next/previous
echo "</p><p>";

$last_page = 1;
while (
$last_page * $links_per_page < count($links) + 1)
 
$last_page += 1;

if (
$_GET["page"] > 2)
 
$previous = '<a href="' . $_SERVER["SCRIPT_URL"] . '">&lt;&lt; First</a> <a href="' . $_SERVER["SCRIPT_URL"] . '?page=' . ($_GET["page"] - 1) . '">&lt; Previous</a> ';
else if (
$_GET["page"] == 2)
 
$previous = '<a href="' . $_SERVER["SCRIPT_URL"] . '">&lt; Previous</a> ';

if (
$_GET["page"] == $last_page)
 
$i = max($_GET["page"] - 4,1);
else if (
$_GET["page"] - 1 == $last_page)
 
$i = max($_GET["page"] - 3,1);
else
 
$i = max($_GET["page"] - 2,1);
$end = min($last_page,$i + 4);

while (
$i <= $end) {
 if (
$i == $_GET["page"])
&
#160; $numbers .= "$i ";
 
else if ($i == 1)
&
#160; $numbers .= '<a href="' . $_SERVER["SCRIPT_URL"] . '">' . $i . '</a> ';
 
else
&
#160; $numbers .= '<a href="' . $_SERVER["SCRIPT_URL"] . '?page=' . $i . '">' . $i . '</a> ';
 
$i += 1;
}

if (
$_GET["page"] < $last_page - 1)
 
$next = '<a href="' . $_SERVER["SCRIPT_URL"] . '?page=' . ($_GET["page"] + 1) . '">Next &gt;</a> <a href="' . $_SERVER["SCRIPT_URL"] . '?page=' . $last_page . '">Last &gt;&gt;</a>';
else if (
$_GET["page"] < $last_page)
 
$next = '<a href="' . $_SERVER["SCRIPT_URL"] . '?page=' . $last_page . '">Next &gt;</a>';

if (
$last_page != 1)
 echo
$previous . $numbers . $next;

echo
"</p>";
// script created by Myles Grey (www.programmersdelight.com)
?>


<p style="font-size: x-small; font-style: italic">Script created by <a href="http://www.programmersdelight.com/">Myles Grey</a>.</p>
<!-- script created by Myles Grey (www.programmersdelight.com) -->
</body>
</html>

This is version 1.1 after a minor bug fix.
« Last Edit: July 20, 2008, 02:35:03 PM by Myles Grey » Logged

IE has the best Quirks
Almost every site you see runs on Quirks, not standards




Remember to mark your topic as [resolved]
Pages: [1]   Go Up
Send this topic | Print
Jump to: