Jump to content

nagyln

New Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by nagyln

  1. I've been working around with it and I think that could be the issue: <div class="pag"> <?php if($page > 1) {?> <li> <?php echo '<a class="paging" href="?search=&submit=?page=' . ($page - 1) . '">Back</a>';?></li> <?php } $start = max(1, $page - 2); $end = min($number_of_pages, $page + 2); for($p = $start; $p <= $end; $p++) {?> <li class="active_pag<?php echo $p==$page ? ' active' : ''; ?>"> <?php echo '<a class="paging" href="?search=&submit=?page=' . $p . '">' . $p . '</a> ';?></li> <?php } if($number_of_pages > $page) {?> <li> <?php echo '<a class="paging" href="?search=&submit=?page=' . ($page + 1) . '">Forward</a>';?></li> <?php } ?> </div> The "href="?search=&submit=?page=" part might be the black sheep. First, I do not get the values from the search when I switch pages. Second, when I do this, now the errors disappeared, the URL changes but the actual results do not. Do you know how to fix that?
  2. I am fairly new and incompetent when it comes to PHP, so my question might be dumb. Sorry if it is. I'd like to have a pagination on my search results because anytime there are many results, the page loads really slow. The website is connected to a phpmyadmin database. This is how my pagination coding looks like: <?php require 'partials/header.php'; //navigation and database connection if (isset($_GET['search']) && isset($_GET['submit'])) { $search = filter_var($_GET['search'], FILTER_SANITIZE_FULL_SPECIAL_CHARS); $query = "SELECT * FROM posts WHERE title LIKE '%$search%' ORDER BY date_time DESC"; $posts = mysqli_query($connection, $query); } //if i don't comment this one out for the pagination: Cannot modify header information - headers already sent else { header('location: ' . ROOT_URL . 'index.php'); die(); } ?> //pagination <?php $searches_per_page = 20; $number_of_searches = mysqli_num_rows($posts); $number_of_pages = ceil($number_of_searches/$searches_per_page); if(!isset($_GET['page'])) { $page = 1; } else { $page = $_GET['page']; } $this_page_first_searches = ($page - 1) * $searches_per_page; $query = "SELECT * FROM posts WHERE title LIKE '%$search%' ORDER BY date_time DESC LIMIT " . $this_page_first_searches . ', ' . $searches_per_page; $posts = mysqli_query($connection, $query); ?> The HTML part is 100% working correctly, the only issue that I'm struggling with is that everytime I switch to another page through my pagination, it gives an error with these messages: I am sorry if my explanation is unclear, I tried my best. So, the pagination gets displayed correctly, the first result page works well too, but as soon as I click to page 2, the warnings above are getting displayed. I have no idea how to fix this issue. Does anyone have an idea what to do?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.