mysql - PHP paginate not effective -
i'm having problem pagination. 5 records per page, next page empty. code. find hard solve problem. can help me solve problem. need help.
<td><b>select section:</b></td> <td><select name="level"> <option value="nursery">nursery</option> <option value="k-1">k-1</option> <option value="k-2">k-2</option> <option value="grade 1">grade 1</option> <option value="grade 2">grade 2</option> <option value="grade 3">grade 3</option> <option value="grade 4">grade 4</option> <option value="grade 5">grade 5</option> <option value="grade 6">grade 6</option> <option value="please_select" selected="selected" id="ps">please select</option> </select></td> <td><input type='image' name='submit' src='images/search1.jpg' id='img11' value='search'/></td> <span class='label'> </span> </tr> @$page = (int) $_get['page']; if ($page < 1) $page = 1; $numpages = 6; $resultsperpage = 5; $startresults = ($page - 1) * $resultsperpage; $numberofrows = mysql_num_rows(mysql_query('select * students')); $totalpages = ceil($numberofrows / $resultsperpage); $id=1; $sql="select * students level = '$level' limit $startresults, $resultsperpage"; $result=mysql_query($sql); while ($row = mysql_fetch_assoc($result)){ if($level == ""){ echo "<script>alert(\"please come in year level!\");</script>"; homecoming 'student_list'; } else{ echo "<tr class='tr1'>"; echo "<center>"; echo "<td class='1'>" . $row['surname'] .", " .$row['firstname']." ". $row['middlename']. "</td>"; echo "<td class='1'>". $row['level'] . "</td>"; echo "</center>"; echo "</tr>"; } } $id++; $boundarypages = floor($numpages / 2); $range = array('start' => 1, 'end' => $totalpages); $even = ($numpages % 2 == 0); $theend = $totalpages - $boundarypages; if($even) $theend++; if($totalpages > $numpages) { if($page <= $boundarypages) $range['end'] = $numpages; elseif ($page >= $theend) $range['start'] = $totalpages - $numpages + 1; else { $range['start'] = $page - $boundarypages; $range['end'] = $page + $boundarypages; if($even) $range['end']--; } } if($page > 1) echo '<a href="?page='.($page - 1).'">«</a> '; ($i = $range['start']; $i <= $range['end']; $i++) { if($i == $page) echo '<strong>'.$i.'</strong> '; else echo '<a href="?page='.$i.'">'.$i.'</a> '; } if ($page < $totalpages) echo '<a href="?page='.($page + 1).'">»</a> ';
php mysql phpmyadmin
No comments:
Post a Comment