I am doing course assignment that requires me to paginate a table of student Names and ages. My objective is to make [Previous] [1] [2] [3] [Next] links and to display 5 or less students per page. I need help making the links.
[1] [2] [3] may change depending on pages count or the current page...
This is my code:
<form method="get">
<div>
Delimeter:
<select name="delimeter">
<option value=",">,</option>
<option value="|">|</option>
<option value="&">&</option>
</select>
</div>
<div>
Names:
<input type="text" name="names"/>
</div>
<div>
Ages:
<input type="text" name="ages"/>
</div>
<div>
<input type="submit" name="filter" value="Filter!">
</div>
</form>
<?php
if(isset($_GET['filter'])){
$delimeter = $_GET['delimeter'];
$Names = explode($delimeter,$_GET['names']);
$Ages = explode($delimeter,$_GET['ages']);
$PagesCnt = floor(count($Names)/5)+1;
$SelectedPage = 1;
}
?>
<?php if (isset($Names,$Ages)): ?>
<table border="1" cellpadding="0">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<?php for ($i = 5*($SelectedPage-1); $i < 5*$SelectedPage;$i++): //displays five students per page
if($i>=count($Names)){break;}
?>
<tr>
<td><?=$Names[$i]?></td>
<td><?=$Ages[$i]?></td>
</tr>
<?php endfor;?>
</tbody>
</table>
<?php endif;?>
//I need pagination here!
Aucun commentaire:
Enregistrer un commentaire