Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - CSV header displayed twice in first page of pagination
    primarykey
    data
    text
    <p>I am new to PHP and trying to display the CSV data in a tabular format in my web page with pagination option. This is the code I have so far. </p> <pre><code>&lt;?php $names = file('demo.csv'); $page = $_GET['page']; $pagedResults = new Paginated($names, 20, $page); echo "&lt;table border='2' bgcolor='#fbd998' style='float:center; margin:20'&gt;"; //when $row is false loop terminates while ( $row = $pagedResults-&gt;fetchPagedRow()) { echo "&lt;tr&gt;&lt;td&gt;"; $row1 = str_replace( ',', "&lt;/td&gt;&lt;td&gt;", $row ); echo $row1; echo "&lt;/td&gt;&lt;/tr&gt;"; } echo "&lt;/table&gt;"; //important to set the strategy to be used before a call to fetchPagedNavigation $pagedResults-&gt;setLayout(new DoubleBarLayout()); echo $pagedResults-&gt;fetchPagedNavigation(); ?&gt; </code></pre> <p>The problem was, I was not able to display the CSV header information except the first page. To avoid this, I used the handler to extract the first line alone from CSV file (which contains the header information). I added the below piece of code before the while loop. </p> <pre><code>if (($data = fgetcsv($handle, 1000, ',')) !== FALSE) { } echo "&lt;table border='2' bgcolor='#fbd998' style='float:center; margin:20'&gt;"; echo '&lt;tr&gt;&lt;th&gt;'.implode('&lt;/th&gt;&lt;th&gt;', $data).'&lt;/th&gt;&lt;/tr&gt;'; </code></pre> <p>This strategy seems to be working fine in all the pages except that in the first page, I have the CSV header twice. For example, my current first page looks like below. </p> <ul> <li>Column1 Column2 Column3 </li> <li><p>Column1 Column2 Column3 </p> <hr></li> <li><p>Rest of my data </p> <hr></li> </ul> <p>Can someone please guide me on how to resolve this problem?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload