<html>
<head>
<link href="style/main.css" rel="stylesheet" text="text/css">
</head>
<body>
<?php
//Paging. Not the most optimized solution, but it works :)
//Written by Sindre Mathisen
class xmlreader {
var $navn; // <navn></navn>
var $email; // <email></email>
var $beskjed; // <melding></melding>
function xmlreader ($aa) {
foreach ($aa as $k=>$v)
$this->$k = $aa[$k];
}
}
function readDatabase($filename) {
// read the xml "database"
$data = implode("",file($filename));
$parser = xml_parser_create();
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
xml_parse_into_struct($parser,$data,$values,$tags);
xml_parser_free($parser); // loop through the structures
foreach ($tags as $key=>$val) {
//hvis det er en start node
if ($key == "melding") {
$molranges = $val;
for ($i=0; $i < count($molranges); $i+=2) {
$offset = $molranges[$i] + 1;
$len = $molranges[$i + 1] - $offset;
$tdb[] = parse(array_slice($values, $offset, $len));
}
} else {
continue;
}
}
return $tdb;
} function parse($mvalues) {
for ($i=0; $i < count($mvalues); $i++)
$mol[$mvalues[$i]["tag"]] = $mvalues[$i]["value"];
return new xmlreader($mol);
} $db = readDatabase("mynews.xml");
echo "Utskrift over mynews.xml:\n";
//print_r($db);
$perside = 4;
$mange = count ($db);
echo $mange;
if ($mange <= $perside)
{
//vi onsker en sjekk pa om det er FERRE en perside
$perside = $mange;
}
else
{
$hei = $neste - $perside;
}
if ($neste==0)
{
$neste = $perside;
}
if ($neste!=0)
{
$fra = $neste - $perside;
}
else
{
$fra = 0;
}
for($kk=$fra; $kk < $neste; $kk++)
{
if(strcasecmp($db[$kk]->navn,""))
{
echo "<table border=1 width=300><tr><td><strong>Navn:</strong></td><td>";
echo $db[$kk]->navn;
echo "</td></tr><tr><td><strong>Email:</strong></td><td>";
echo $db[$kk]->email;
echo "</td></tr><tr><td><strong>Beskjed</strong></td><td>";
echo $db[$kk]->beskjed;
echo "</td></tr></table><br><br>";
}
}
$old = $neste;
$neste = $neste + $perside;
if ($fra != 0)
{
?>
<p>
<a href="<? echo $PHP_SELF;?>?neste=<?echo $neste - $perside - $perside; ?>">Forrige <? echo $perside; ?></a>
<?
}
if($old < $mange)
{
?>
<a href="<? echo $PHP_SELF;?>?neste=<?echo $neste; ?>">Neste <? echo $perside; ?></a>
<?
}
?>
</p>
</body>
</html>