Some PHP tutorials

August 9th, 2006

Not so much tutorial than some random code I just wrote to help me with somthing else…


<?php
error_reporting(E_ALL ^ E_NOTICE);

/*
set some vars
*/

$n = 0;
$max = $_GET['max'];

if (isset($_GET['current'])){

$min = $_GET['current'];

}else{

$min = 0;

}

if (!isset($max)){

$max = 10;

}

/*
lets get some data to work with.
fills an array with 1000 items.
*/

$entries = array();

for ($i = 1; $i <= 1000; $i++) {
$entries[$i] = $i;
}

/*
print the current results
*/

foreach($entries as $entry){

if ($n <= ($max-1)){

if (!($n < $min)){

echo $entry;

}

$n++;
}

}

/*
if we are not on first page of results
show a back button
*/

if ($n > 10){
echo "<br/>";
$min = $n-20;
$bmax = $max - 10;
echo '<a href="?current=' . $min . '&max=' . $bmax  . '">Previous</a>';
}
/*
print link to get next ten entries
*/

echo "<br/>";
$max = $max + 10;
echo '<a href="?current=' . $n . '&max=' . $max  . '">Next</a>';

?>

¬ SHARE

Tags: ,

Leave a Reply

A little knowledge that acts is worth infinitely more than much knowledge that is idle. – Kahlil Gibran

Link Love

  • BubblesSOC

About Photogabble

Photogabble has been developed, edited and written by Simon Dann. Simon is a 22 year old post-grad Communication, Culture & Media student, currently studying for his Masters.

Like this Website?

If you like this website you can subscribe to the feed, or recieve email updates.

TwitterCounter for @carbontwelve