Make my pet project (war criminals database-Ukranian War). And have problem with paggination- the Previus dont work( the error ).(Fatal error: Uncaught PDOException: SQLSTATE[42000]). Another parts working.
Here my controller function
public function Latest_Items()
{include 'C:\xampp\htdocs\WarCriminalsDatabase\database_connection.php';
$paginations=$this->i_model->paginations;
// $page_counter=$this->i_model->page_counter;
$start=$this->i_model->start;
$perPage=$this->i_model->perPage;
$pagLink=$this->i_model->pagLink;
if (!isset($_GET['items'])) {
$paginations-$this->i_model->pugination($conn);
$pokidky = $this->i_model->get_all_pokidky_pagination($conn);
$category = $this->c_model->get_all_category($conn);
include 'Views\MainPageView.php';
}
}
Here The functions in Model class.
function pugination($conn)
{
$this->start = 1;
$this->perPage = 4;
$this->page_counter = 1;
if (isset($_GET['start'])) {
$this->start = $_GET['start'];
//$this->offset = $this->start* $this->perPage = 8;
// $this->page_counter = $_GET['start'];
$this->start = $this->start * $this->perPage;
// $this->next = $this->page_counter + 1;
// $this->previous = $this->page_counter - 1;
}
else {
$this->start = 1;
}
$count_query = "SELECT * FROM pokidky ORDER by id ASC";
$query = $conn->prepare($count_query);
$query->execute();
$count = $query->rowCount();
// calculate the pagination number by dividing total number of rows with per page.
$this->paginations = ceil($count / $this->perPage);
return $this->paginations;
}
function get_all_pokidky_pagination($conn)
{
$this->pugination($conn);
$this->start = 1;
$this->perPage = 4;
$this->page_counter = 1;
if (isset($_GET['start'])) {
$this->start = $_GET['start'];
//$this->offset = $this->start* $this->perPage = 8;
// $this->page_counter = $_GET['start'];
$this->start = ($this->start * $this->perPage) ;
// $this->next = $this->page_counter + 1;
// $this->previous = $this->page_counter - 1;
}
else {
$this->start = 1;
}
$sql = "SELECT * FROM pokidky ORDER by id ASC LIMIT $this->start, $this->perPage";
$stmt = $conn->prepare($sql);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$pokidky = $stmt->fetchAll();
} else {
$pokidky = 0;
}
return $pokidky;
}
The html part in View page.
<pre>
<nav aria-label="Page navigation example">
<ul class="pagination">
<li class="page-item" <?php if ($start <= 1) {
echo 'disabled';
} ?>><a class="page-link" href="<?php if ($start >= 1)
{ echo '#'; } else { echo "?start=" . ($start - 1);
} ?>">Previous</a></li>
<li class="page-item"><a class="page-link" href="?start=0">First</a></li>
<li class="page-item" <?php if ($start >= 1) {
echo 'disabled';
} ?>><a class="page-link" href="<?php if ($start >= 1) {
echo '#';
} else {
echo "?start=" . ($start + 1);
} ?>">Next</a></li>
<li class="page-item"><a class="page-link" href="?pagination=<?php echo $paginations; ?>">Last</a></li>
</ul>
</nav>
</pre
will be glad if you help me. Admins please dont bann me. Maybe my questions is stupid, but I think that no stupid questions, couse this site for asking help, simple or hard all questions are matter. Also I will be glad if you explain me all in very simle words, my english not very good, I very sorry for it.