ncoo
asked on
CSV - Display Values
I'm trying to make a php script to output a csv file.
What I'd like to happen is to have a max of 10 results per page, and a next page previous page option.
This is the code I've got so far, it may be simpler to just start again I don't mind either away. Just as long as the list is split into the same elements.
<?php
$filename = "example.csv";
$id = fopen($filename, "r"); //open the file
while ($data = fgetcsv($id, filesize($filename))) //start a loop
$table[] = $data;
fclose($id); //close file
echo "<table>\n";
foreach($table as $row)
{
echo "<tr>";
foreach($row as $data)
list ($key_number, $title, $sub_title, $category, $extra, $x, $y) = $line;
echo "<td>$key_number</td><td>$ title</td> ";
echo "</tr>\n";
}
echo "</table>\n";
?>
What I'd like to happen is to have a max of 10 results per page, and a next page previous page option.
This is the code I've got so far, it may be simpler to just start again I don't mind either away. Just as long as the list is split into the same elements.
<?php
$filename = "example.csv";
$id = fopen($filename, "r"); //open the file
while ($data = fgetcsv($id, filesize($filename))) //start a loop
$table[] = $data;
fclose($id); //close file
echo "<table>\n";
foreach($table as $row)
{
echo "<tr>";
foreach($row as $data)
list ($key_number, $title, $sub_title, $category, $extra, $x, $y) = $line;
echo "<td>$key_number</td><td>$
echo "</tr>\n";
}
echo "</table>\n";
?>
$i could be renamed to '$currentrow' to make the code more readable.
ASKER
That doesn't really work. That's why it may be best to start the code from the begining, if I explain the problem fully hopefully it will help.
I've got a CSV file, I want to display this with 10 results per page. Idealy I'd like the next tag and previous tag to only appear when need, I.e. so the previous tag doesn't appear at the start of the file, I'd also like some page numbers at the bottom to help skip through the file (I don't know if you've herd of pager.php but this covers this part of the script but I've never worked out how to use it correctly).
I hope that explains the problem better.
I've got a CSV file, I want to display this with 10 results per page. Idealy I'd like the next tag and previous tag to only appear when need, I.e. so the previous tag doesn't appear at the start of the file, I'd also like some page numbers at the bottom to help skip through the file (I don't know if you've herd of pager.php but this covers this part of the script but I've never worked out how to use it correctly).
I hope that explains the problem better.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
'pagestart' will be a parameter, probably received using the GET method, with a default of 0. Your 'next' link should point to itself with pagestart=pagestart+10 and the 'previous' link with pagestart=pagestart-10. Here is a quick and dirty example:
$pagestart = $_GET['pagestart'];
$i = 0;
foreach($table as $row)
{
if ($i >= $pagestart) {
/* print the row */
}
if ($i >= $pagestart + 10)
break;
$i = $i + 1;
}
echo "<a href=\"me.php?pagestart=".
echo "<a href=\"me.php?pagestart=".