arrays - PHP - refreshing page and showing different rows in a table -
<?php //if pagenum isset figure out start(7 rows per page * page num +1 $pagenum = isset($_get['pagenum']) ? (int)$_get['pagenum'] : 0; $startrow = $pagenum == 0 ? 0 : ($pagenum * 7 + 1); $endrow = $startrow + 7; $count = 0; while (($data = fgetcsv($handle, 1000, ";")) !== false) { if($count >= $startrow) echo ' aantal vervangingen: 30'; $row = 1; if (($handle = fopen("vervangingen.csv", "r")) !== false) { echo '<table border="1">'; while (($data = fgetcsv($handle, 1000, ";")) !== false) { $num = count($data); if ($row == 1) { echo '<tr>'; }else{ echo '<tr>'; } ($c=0; $c < $num; $c++) { //echo $data[$c] . "<br />\n"; if(empty($data[$c])) { $value = " "; }else{ $value = $data[$c]; } if ($row == 1) { echo '<th>'.$value.'</th>'; }else{ echo '<td>'.$value.'</td>'; } } if ($row == 1) { echo '</tr></thead><tbody>'; }else{ echo '</tr>'; } $row++; } echo '</tbody></table>'; fclose($handle); } if($count == $endrow) { //wait 3 seconds use javascript redirect. sleep(3); echo '<script>window.loaction.href="theurl?pagenum='.($pagenum +1).'"</script>'; } } ?>
i made table in php gets data .csv file. question is, how let php show first 7 rows, should refresh page , show following 7 rows, there 30 in total. once has shown rows, should still refresh page , start on again.
how do this? know how refresh php page, showing 7 rows per refresh quite hard. help?
greetings
the following (tested) uses php sessions , js settimeout.
interesting, wonder if ever use effect. (i unable save $handle session variable.)
<?php // z1.php file, z1.csv data file session_start(); echo <<<eod <body onload="settimeout('f1();',3000);"> <script type="text/javascript"> function f1() { window.location.replace("z1.php"); } </script> eod; if (isset($_session['sessrow1st'])) { $row1st = $_session['sessrow1st']; } else { $row1st = 1; } $handle = fopen("z1.csv", "r"); if ($handle === false) { exit("open error"); }; echo "<table border='1'>\n"; $rownum = 0; while (($data = fgetcsv($handle, 1000, ";")) !== false) { $rownum += 1; if ($rownum < $row1st) continue; if ($rownum > $row1st+6) break; $numcols = count($data); echo '<tr>'; ($c=0; $c < $numcols; $c++) { if(empty($data[$c])) { $value = " "; } else { $value = $data[$c]; } echo '<td>'.$value.'</td>'; } echo "</tr>\n"; } echo '</table></body>'; if (feof($handle)) { $rownum = 1; } fclose($handle); $_session['sessrow1st'] = $rownum; ?>
Comments
Post a Comment