Pancras Suday
JF-Expert Member
- Jun 24, 2011
- 8,144
- 3,848
Hizi code zinafanya kazi bila error yoyote ya SQL au PHP (no browser error), tatizo linakuja ninapoweka pagination tu, kwa records za kwanza hakuna tatizo ila unapojaribu kubonyeza "NEXT LIST" ili iweze kudisplay records zinazofuata kulingana na limit ya records, page inaloop mpaka page 12 ambapo kwa calculation ya kawaida hakuna idadi ya hizo page kulingana na idadi ya rows zangu kwenye database yangu, mimi nimeweka iwe ina-increment kwa 1 kwa maana hiyo inatakiwa ioneshe page namba 2 instead page 12 hebu mnisaidie ni wapi nimemess up
<?php
include("includes/connect.php");
//pagination start
$start = 0;
$limit = 7;
if (isset($_GET['id'])) {
$id = $_GET['id'];
$start = ($id - 1)*$limit;
}else{
$id = 1;
}
// query records from database limit by 7 records only
$sql = "SELECT id, note, td_date, td_time FROM to_do LIMIT ? , ?";
$statement = $conn->prepare($sql);
$statement->bind_param("ii",$start,$limit);
$statement->execute();
$statement->store_result();
$numrows = $statement->num_rows();
$statement->bind_result($id,$note,$td_date,$td_time);
if($numrows > 0){
?>
<table class="table table-hover">
<thead>
<tr>
<th>Action</th>
<th>Date</th>
<th>Time</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
while ($statement->fetch()){
echo "<tr>";
echo"<td> ". $note ."</td>";
echo "<td>". $td_date ."</td>";
echo "<td>". $td_time ."</td>";
echo"<td><a href='to_do.php?del=$id' style='text-align:center'> <span class='glyphicon glyphicon-ok'></span></a></td>";
echo "</tr>";
}
?>
</tbody>
</table>
<ul class="pagination">
<?php
//fetch all the data from database to get number of rows
$query = "SELECT note, td_date, td_time FROM to_do";
$statement = $conn->prepare($query);
$statement->execute();
$statement->store_result();
$rows = $statement->num_rows();
//calculate total page number for the given table in the database
$total = ceil($rows/$limit);
if($total!=1){
if($id>1){
//Go to previous page to show previous 7 items. If its in page 1 then it is inactive
echo "<li><a href='?id=".($id-1)."' class='button'>PREVIOUS LIST</a></li>";
}
if($id!=$total){
////Go to previous page to show next 7 items.
echo "<li><a href='?id=".($id+1)."' class='button'>NEXT LIST</a></li>";
}
}
?>
</ul>
<?php
}else{
echo "<h4 style='color:[HASHTAG]#ff1635[/HASHTAG];'>There is no To-Do to display</h4>";
}
?>
NB: Hakuna kosa lolote linalodisplay kwenye browser kuwa nimekosea sehemu
<?php
include("includes/connect.php");
//pagination start
$start = 0;
$limit = 7;
if (isset($_GET['id'])) {
$id = $_GET['id'];
$start = ($id - 1)*$limit;
}else{
$id = 1;
}
// query records from database limit by 7 records only
$sql = "SELECT id, note, td_date, td_time FROM to_do LIMIT ? , ?";
$statement = $conn->prepare($sql);
$statement->bind_param("ii",$start,$limit);
$statement->execute();
$statement->store_result();
$numrows = $statement->num_rows();
$statement->bind_result($id,$note,$td_date,$td_time);
if($numrows > 0){
?>
<table class="table table-hover">
<thead>
<tr>
<th>Action</th>
<th>Date</th>
<th>Time</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
while ($statement->fetch()){
echo "<tr>";
echo"<td> ". $note ."</td>";
echo "<td>". $td_date ."</td>";
echo "<td>". $td_time ."</td>";
echo"<td><a href='to_do.php?del=$id' style='text-align:center'> <span class='glyphicon glyphicon-ok'></span></a></td>";
echo "</tr>";
}
?>
</tbody>
</table>
<ul class="pagination">
<?php
//fetch all the data from database to get number of rows
$query = "SELECT note, td_date, td_time FROM to_do";
$statement = $conn->prepare($query);
$statement->execute();
$statement->store_result();
$rows = $statement->num_rows();
//calculate total page number for the given table in the database
$total = ceil($rows/$limit);
if($total!=1){
if($id>1){
//Go to previous page to show previous 7 items. If its in page 1 then it is inactive
echo "<li><a href='?id=".($id-1)."' class='button'>PREVIOUS LIST</a></li>";
}
if($id!=$total){
////Go to previous page to show next 7 items.
echo "<li><a href='?id=".($id+1)."' class='button'>NEXT LIST</a></li>";
}
}
?>
</ul>
<?php
}else{
echo "<h4 style='color:[HASHTAG]#ff1635[/HASHTAG];'>There is no To-Do to display</h4>";
}
?>
NB: Hakuna kosa lolote linalodisplay kwenye browser kuwa nimekosea sehemu