php mysqli table pagination












0














I'm trying to create a pagination for our status table but the records being displayed is not on par with the records that I want to display. Here's my code:



<?php

$query = mysqli_query($connect,"SELECT * FROM inventory_item ") or die ("Error: Could not fetch rows!");
$count = 0;

if (isset($_GET['page_no']) && $_GET['page_no']!="") {
$page_no = $_GET['page_no'];
} else {
$page_no = 1;
}

$total_records_per_page = 3;
$offset = ($page_no-1) * $total_records_per_page;
$previous_page = $page_no - 1;
$next_page = $page_no + 1;
$adjacents = "2";

$query_count = mysqli_query($connect,"SELECT COUNT(*) As total_records FROM `inventory_item`");
$total_records = mysqli_fetch_array($query_count);
$total_records = $total_records['total_records'];
$total_no_of_pages = ceil($total_records / $total_records_per_page);
$second_last = $total_no_of_pages - 1;

$result = mysqli_query($connect,"SELECT * FROM `inventory_item` LIMIT $offset, $total_records_per_page");
while ($row = mysqli_fetch_array($query))
{

$item_name = $row ['item_name'];
echo '<tr><td>'.$row['item_name']. '</td><td>'.$row['description']. '</td><td>'.$row['unit'].'</td>
<td>'.$row['quantity']. '</td><td>'.$row['price']. '</td>
<td>'.$row['price'] * $row['quantity'].'</td>
<td>'.$row['status'].'</td>
<td><a href="inventory_statusEditRecordsFinal1.php?CO='.$item_name.'" title="Click to edit records" class="buttonn"/> Edit </a></td>
<td><a href="inventory_deletestatusFinal.php?item_name='.$item_name.'" title="Click to delete records" class="delbutton" onclick="return ConfirmDelete()"/> Delete </a></td>

</tr>';


}
mysqli_close($connect);

?>


Here's the result, I wanted to display 3 records per page but it displays all the data.










share|improve this question
























  • How about the result? It's duplicate or display for wrong page_no?
    – Van Tho
    Nov 23 at 4:01










  • @VanTho I edited my post and added a picture of the result
    – Riiic
    Nov 23 at 4:04










  • change $query to $result in while condition.
    – Android Gears
    Nov 23 at 4:08
















0














I'm trying to create a pagination for our status table but the records being displayed is not on par with the records that I want to display. Here's my code:



<?php

$query = mysqli_query($connect,"SELECT * FROM inventory_item ") or die ("Error: Could not fetch rows!");
$count = 0;

if (isset($_GET['page_no']) && $_GET['page_no']!="") {
$page_no = $_GET['page_no'];
} else {
$page_no = 1;
}

$total_records_per_page = 3;
$offset = ($page_no-1) * $total_records_per_page;
$previous_page = $page_no - 1;
$next_page = $page_no + 1;
$adjacents = "2";

$query_count = mysqli_query($connect,"SELECT COUNT(*) As total_records FROM `inventory_item`");
$total_records = mysqli_fetch_array($query_count);
$total_records = $total_records['total_records'];
$total_no_of_pages = ceil($total_records / $total_records_per_page);
$second_last = $total_no_of_pages - 1;

$result = mysqli_query($connect,"SELECT * FROM `inventory_item` LIMIT $offset, $total_records_per_page");
while ($row = mysqli_fetch_array($query))
{

$item_name = $row ['item_name'];
echo '<tr><td>'.$row['item_name']. '</td><td>'.$row['description']. '</td><td>'.$row['unit'].'</td>
<td>'.$row['quantity']. '</td><td>'.$row['price']. '</td>
<td>'.$row['price'] * $row['quantity'].'</td>
<td>'.$row['status'].'</td>
<td><a href="inventory_statusEditRecordsFinal1.php?CO='.$item_name.'" title="Click to edit records" class="buttonn"/> Edit </a></td>
<td><a href="inventory_deletestatusFinal.php?item_name='.$item_name.'" title="Click to delete records" class="delbutton" onclick="return ConfirmDelete()"/> Delete </a></td>

</tr>';


}
mysqli_close($connect);

?>


Here's the result, I wanted to display 3 records per page but it displays all the data.










share|improve this question
























  • How about the result? It's duplicate or display for wrong page_no?
    – Van Tho
    Nov 23 at 4:01










  • @VanTho I edited my post and added a picture of the result
    – Riiic
    Nov 23 at 4:04










  • change $query to $result in while condition.
    – Android Gears
    Nov 23 at 4:08














0












0








0







I'm trying to create a pagination for our status table but the records being displayed is not on par with the records that I want to display. Here's my code:



<?php

$query = mysqli_query($connect,"SELECT * FROM inventory_item ") or die ("Error: Could not fetch rows!");
$count = 0;

if (isset($_GET['page_no']) && $_GET['page_no']!="") {
$page_no = $_GET['page_no'];
} else {
$page_no = 1;
}

$total_records_per_page = 3;
$offset = ($page_no-1) * $total_records_per_page;
$previous_page = $page_no - 1;
$next_page = $page_no + 1;
$adjacents = "2";

$query_count = mysqli_query($connect,"SELECT COUNT(*) As total_records FROM `inventory_item`");
$total_records = mysqli_fetch_array($query_count);
$total_records = $total_records['total_records'];
$total_no_of_pages = ceil($total_records / $total_records_per_page);
$second_last = $total_no_of_pages - 1;

$result = mysqli_query($connect,"SELECT * FROM `inventory_item` LIMIT $offset, $total_records_per_page");
while ($row = mysqli_fetch_array($query))
{

$item_name = $row ['item_name'];
echo '<tr><td>'.$row['item_name']. '</td><td>'.$row['description']. '</td><td>'.$row['unit'].'</td>
<td>'.$row['quantity']. '</td><td>'.$row['price']. '</td>
<td>'.$row['price'] * $row['quantity'].'</td>
<td>'.$row['status'].'</td>
<td><a href="inventory_statusEditRecordsFinal1.php?CO='.$item_name.'" title="Click to edit records" class="buttonn"/> Edit </a></td>
<td><a href="inventory_deletestatusFinal.php?item_name='.$item_name.'" title="Click to delete records" class="delbutton" onclick="return ConfirmDelete()"/> Delete </a></td>

</tr>';


}
mysqli_close($connect);

?>


Here's the result, I wanted to display 3 records per page but it displays all the data.










share|improve this question















I'm trying to create a pagination for our status table but the records being displayed is not on par with the records that I want to display. Here's my code:



<?php

$query = mysqli_query($connect,"SELECT * FROM inventory_item ") or die ("Error: Could not fetch rows!");
$count = 0;

if (isset($_GET['page_no']) && $_GET['page_no']!="") {
$page_no = $_GET['page_no'];
} else {
$page_no = 1;
}

$total_records_per_page = 3;
$offset = ($page_no-1) * $total_records_per_page;
$previous_page = $page_no - 1;
$next_page = $page_no + 1;
$adjacents = "2";

$query_count = mysqli_query($connect,"SELECT COUNT(*) As total_records FROM `inventory_item`");
$total_records = mysqli_fetch_array($query_count);
$total_records = $total_records['total_records'];
$total_no_of_pages = ceil($total_records / $total_records_per_page);
$second_last = $total_no_of_pages - 1;

$result = mysqli_query($connect,"SELECT * FROM `inventory_item` LIMIT $offset, $total_records_per_page");
while ($row = mysqli_fetch_array($query))
{

$item_name = $row ['item_name'];
echo '<tr><td>'.$row['item_name']. '</td><td>'.$row['description']. '</td><td>'.$row['unit'].'</td>
<td>'.$row['quantity']. '</td><td>'.$row['price']. '</td>
<td>'.$row['price'] * $row['quantity'].'</td>
<td>'.$row['status'].'</td>
<td><a href="inventory_statusEditRecordsFinal1.php?CO='.$item_name.'" title="Click to edit records" class="buttonn"/> Edit </a></td>
<td><a href="inventory_deletestatusFinal.php?item_name='.$item_name.'" title="Click to delete records" class="delbutton" onclick="return ConfirmDelete()"/> Delete </a></td>

</tr>';


}
mysqli_close($connect);

?>


Here's the result, I wanted to display 3 records per page but it displays all the data.







php mysqli pagination






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 at 4:19









Alive to Die

55.4k82868




55.4k82868










asked Nov 23 at 3:53









Riiic

11




11












  • How about the result? It's duplicate or display for wrong page_no?
    – Van Tho
    Nov 23 at 4:01










  • @VanTho I edited my post and added a picture of the result
    – Riiic
    Nov 23 at 4:04










  • change $query to $result in while condition.
    – Android Gears
    Nov 23 at 4:08


















  • How about the result? It's duplicate or display for wrong page_no?
    – Van Tho
    Nov 23 at 4:01










  • @VanTho I edited my post and added a picture of the result
    – Riiic
    Nov 23 at 4:04










  • change $query to $result in while condition.
    – Android Gears
    Nov 23 at 4:08
















How about the result? It's duplicate or display for wrong page_no?
– Van Tho
Nov 23 at 4:01




How about the result? It's duplicate or display for wrong page_no?
– Van Tho
Nov 23 at 4:01












@VanTho I edited my post and added a picture of the result
– Riiic
Nov 23 at 4:04




@VanTho I edited my post and added a picture of the result
– Riiic
Nov 23 at 4:04












change $query to $result in while condition.
– Android Gears
Nov 23 at 4:08




change $query to $result in while condition.
– Android Gears
Nov 23 at 4:08

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440467%2fphp-mysqli-table-pagination%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440467%2fphp-mysqli-table-pagination%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks