I am parsing my feed file ok and returning the first record. Not being great with php I am struggling to implement a Next link which when clicked would display the next record, any assistance would e greatly appreciated.
<?php
require("MagicParser.php");
$filename = "http://127.0.0.1//parser/magazania_titles.txt";
$format_string = MagicParser_getFormat($filename);
if (!$format_string)
{
print "<p>".MagicParser_getErrorMessage()."</p>";
exit;
}
function myRecordHandler($record)
{global $counter;
// increment counter
$counter++;
print "<table border='1'>";
foreach($record as $key => $value)
{
print "<tr>";
print "<th>".$key."</th>";
print "<td>".htmlentities($value)."
</td>";
print "</tr>";
}
print "</table>";
return ($counter == 1);
}
MagicParser_parse($filename,"myRecordHandler",$format);
?>
Wow, the support for this script is amazing.
Thanks David it worked a charm.
Bill
Hi,
Here's a modified version of your code above that uses a page variable to loop through the records until you reach the one you want to display, together with a "Next" link to the next record (if you have not reached the end).
I've explained the additional code in the comments....
<?php
require("MagicParser.php");
$filename = "http://127.0.0.1//parser/magazania_titles.txt";
$format_string = MagicParser_getFormat($filename);
if (!$format_string)
{
print "<p>".MagicParser_getErrorMessage()."</p>";
exit;
}
// get the current page from the URL
$page = $_GET["page"];
// if not set, force to page 1
if (!$page) $page = 1;
function myRecordHandler($record)
{
global $counter;
global $page;
// increment counter
$counter++;
// return false if counter not yet reached page to view
if ($counter < $page) return false;
print "<table border='1'>";
foreach($record as $key => $value)
{
print "<tr>";
print "<th>".$key."</th>";
print "<td>".htmlentities($value)."
</td>";
print "</tr>";
}
print "</table>";
// return true to stop parsing
return true;
}
MagicParser_parse($filename,"myRecordHandler",$format);
// if possibly more records, create link to next record
// otherwise print end of file message
if ($counter == $page)
{
print "<p><a href='?page=".($page+1)."'>Next</a></p>";
}
else
{
print "<p>No more records.</p>";
}
?>
Hope this helps!
Cheers,
David.