I am new to PHP and, I have a CSV file which, am displaying in my web page. I want the CSV file to be displayed with the pagination option so that the web page would look nice. This is the code I have so far.
<?php
$names = file('demo.csv');
$page = $_GET['page'];
//constructor takes three parameters
//1. array to be paged
//2. number of results per page (optional parameter. Default is 10)
//3. the current page (optional parameter. Default is 1)
$pagedResults = new Paginated($names, 20, $page);
echo "<ul>";
while($row = $pagedResults->fetchPagedRow()) {
//when $row is false loop terminates
echo "<li>{$row}</li>";
}
echo "</ul>";
//important to set the strategy to be used before a call to fetchPagedNavigation
$pagedResults->setLayout(new DoubleBarLayout());
echo $pagedResults->fetchPagedNavigation();
?>
However, the CSV file gets displayed with the commas in the screen. Let us consider the below example. Let's assume we have 40 records in my csv file. The contents of the CSV file are as below.
- Author1,Name1,Name2,email
- 1,John,Smith,[email protected]
- 2,Jack,Gibbs,[email protected]
- 3,Mike,Dell,[email protected]
and so on.
In my web page, I am getting the output in 2 pages (as I have set my pagination option to display 20 records in each page.
$pagedResults = new Paginated($names, 20, $page);
The output however still contains the comma from the original CSV file. I want my output to be like below.
First Page:
- Author1 Name1 Name2 Email
- 1 John Smith [email protected]
and so on.
Second Page:
- Author1 Name1 Name2 Email
and so on.