maviyazilim Posted September 28, 2021 Author Share Posted September 28, 2021 ginerjm Again, I don't understand what you said. I do not want to see the information in these contents. I want to paginate the contents as 10 pieces. 1 2 1 last 10 content 2 top 6 content The pagination will progress as content is added. I want to do pagination. Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590441 Share on other sites More sharing options...
ginerjm Posted September 28, 2021 Share Posted September 28, 2021 Well, then you have to FIX your code so that you can continue working on the OTHER PROBLEM. Good bye. You are not trying to be a programmer. I am giving you Very Simple instructions and you "do not understand". Can't make it any simpler. Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590442 Share on other sites More sharing options...
maviyazilim Posted September 28, 2021 Author Share Posted September 28, 2021 ginerjm. Thank you for your help. bye Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590443 Share on other sites More sharing options...
Barand Posted September 28, 2021 Share Posted September 28, 2021 1 hour ago, maviyazilim said: The line with the error code is below. 43 echo $r['icerik_id'] . ' - ' . $r['name'] . '<br>'; Despite requests, you refused to show any code that output the query results. On top of that you used "SELECT * " which gives us no information whatsoever about the columns you are selecting. As I told you, I created a test "icerik" table. This had columns "icerik_id" and "name" - which is why I output a column called "name". You need to use your column names, whatever they are. 1 Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590444 Share on other sites More sharing options...
maviyazilim Posted September 28, 2021 Author Share Posted September 28, 2021 Barand I have added as a header. sorted the contents. I don't want that. I want to paginate. The titles of the article itself plus the entire table are already listed on the homepage. Clicking on 1 and 2 does not change the homepage at all. thats the problem. There are 16 contents. No matter which page you click on, there is always the last 10 content on the homepage. Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590446 Share on other sites More sharing options...
Barand Posted September 28, 2021 Share Posted September 28, 2021 Are you telling us that the code you posted here is not the code you used to output the list? Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590448 Share on other sites More sharing options...
maviyazilim Posted September 28, 2021 Author Share Posted September 28, 2021 Barand The code you gave works without any errors. It sorts when the content_id and title are typed. This is not what I want, I want to count. The homepage does not change. There is also an extra header and text at the bottom. Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590449 Share on other sites More sharing options...
Barand Posted September 28, 2021 Share Posted September 28, 2021 As you have not shown us this homepage (where the error is showing itself) then you have had us chasing our tails and wasting time on the wrong piece of code. I've had enough. If you're lucky, someone else might take over. Bye. 1 Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590450 Share on other sites More sharing options...
ginerjm Posted September 28, 2021 Share Posted September 28, 2021 Barand - you have much more patience than I. Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590451 Share on other sites More sharing options...
maviyazilim Posted September 28, 2021 Author Share Posted September 28, 2021 Barand. Thank you for your help Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590452 Share on other sites More sharing options...
Barand Posted September 28, 2021 Share Posted September 28, 2021 Just now, ginerjm said: Barand - you have much more patience than I Not unlimited though Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590453 Share on other sites More sharing options...
maviyazilim Posted September 28, 2021 Author Share Posted September 28, 2021 Barand. I can send the files if you want to help. If you let me know your e-mail address, I can send it there. Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590454 Share on other sites More sharing options...
Barand Posted September 28, 2021 Share Posted September 28, 2021 2 minutes ago, maviyazilim said: I can send the files if you want to help. If you let me know your e-mail address, I can send it there. Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590455 Share on other sites More sharing options...
ginerjm Posted September 28, 2021 Share Posted September 28, 2021 This guy just doesn't get it. We've asked for him to post his code several times here and he refused. Now he thinks he can send it to you and have you re-write it for him. Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590456 Share on other sites More sharing options...
maviyazilim Posted September 28, 2021 Author Share Posted September 28, 2021 ginerjm. I did not reject anything. I do not know english. I'm using google translate. I have very little knowledge. I don't understand what you are saying. I will do whatever you want me to write where with details or code samples. I can send you all the files I have if you want. If you say that this much detail and information is not enough. Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590457 Share on other sites More sharing options...
ginerjm Posted September 28, 2021 Share Posted September 28, 2021 If you have trouble with English then this forum could be a problem for you. Time to read some books and teach yourself how to write code. Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590458 Share on other sites More sharing options...
maviyazilim Posted September 28, 2021 Author Share Posted September 28, 2021 i think you are right it was a mistake to ask help from this site. bye everyone. Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590459 Share on other sites More sharing options...
ginerjm Posted September 28, 2021 Share Posted September 28, 2021 Post ALL of your code here. ALL of it. I will copy it from here and see how bad it is. We will start from there. If it is very bad that may help me to help you by knowing what skills you have. One chance. I repeat: ALL OF YOUR CODE. No links. Just code. Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590460 Share on other sites More sharing options...
maviyazilim Posted September 28, 2021 Author Share Posted September 28, 2021 <?php error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); ?> <div id="orta"> <?php $sorgu = mysqli_query($conn,"select * from icerik order by icerik_id desc limit 10"); while($goster=mysqli_fetch_assoc($sorgu)) { echo '<div id="konu">'; echo '<div id="baslik">'; echo $goster['baslik']; echo '</div>'; echo '<div id="yazi">'; echo substr($goster['yazi'],0,300); echo '</div>'; echo '<div id="yazar">'; echo $goster['yazar']; echo '</div>'; echo '</div>'; } ?> <div id="sayfalama"> <?php $results_per_page = 10; $sql='SELECT * FROM icerik'; $result = mysqli_query($conn, $sql); $number_of_results = mysqli_num_rows($result); $number_of_pages = ceil($number_of_results/$results_per_page); if (!isset($_GET['sayfa'])) { $page = 1; } else { $page = $_GET['sayfa']; } $this_page_first_result = ($page-1)*$results_per_page; $sql="SELECT * FROM icerik order by icerik_id desc limit $this_page_first_result, $results_per_page"; $result = mysqli_query($conn, $sql); for ($page=1;$page<=$number_of_pages;$page++) { echo '<a href="index.php?sayfa=' . $page . '">' . $page . '</a> '; } ?> </div> </div> Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590461 Share on other sites More sharing options...
ginerjm Posted September 28, 2021 Share Posted September 28, 2021 Try this: <?php session_start(); error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); $results_per_page = 10; if (!isset($_POST['sayfa'])) { $page = 1; // find total # of rows $sql = 'SELECT * FROM icerik'; $result = mysqli_query($conn, $sql); $number_of_results = mysqli_num_rows($result); $number_of_pages = ceil($number_of_results / $results_per_page); $this_page_first_result = 1; } elseif(isset($_POST['sayfa']) { $page = $_POST['sayfa']; $number_of_pages = $_POST['number_of_pages']; $number_of_results = $_POST['number_of_results']; $this_page_first_result = (($page - 1) * $results_per_page) + 1; } else { echo "Invalid response from page"; // ERROR NO GET, NO POST exit(); } // get set of rows $q = "select * from icerik order by icerik_id desc limit $results_per_page offset $this_page_first_result"; $sorgu = mysqli_query($conn, $q); //******************************* // Show the page echo 'div id="orta">'; // show set of rows while($goster = mysqli_fetch_assoc($sorgu)) { $fld1 = $goster['baslik']; $fld2 = substr($goster['yazi'], 0, 300); $fld3 = $goster['yazar']; $code=<<<heredocs <div id="konu"> <div id="baslik"> $fld1 </div> <div id="yazi" $fld2 </div> <div id="yazar"> $fld3 </div> </div> heredocs; echo $code; } //******************************* // show the form of page numbers echo '<div id="sayfalama">'; echo "<form method='POST' action='index.php'>"; // change to "type='hidden'" after testing echo "<input type='text' name='number_of_pages' value='$number_of_pages'>"; // change to "type='hidden'" after testing echo "<input type='text' name='number_of_results' value='$number_of_results'>"; echo '<br><br>'; for ($i = 1; $i <= $number_of_pages; $i++) { // show page # choices echo "<input type='submit' name='sayfa' value='$i' size=2>"; echo " "; } echo "</form>"; echo "</div>"; // sayfalama echo "</div>"; // orta exit(); Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590466 Share on other sites More sharing options...
Strider64 Posted September 28, 2021 Share Posted September 28, 2021 (edited) Pagination is simple to do, but you need to actually want to learn it. Here's what I call a mini tutorial on how to do it though it uses PDO instead of mysqli, but the principle is the same. Here's a function that I wrote: /* * Pagination Format * Read all the data from the database table in an array format */ function readData($pdo, $table, $page, $perPage, $offset) { $sql = 'SELECT * FROM ' . $table . ' WHERE page=:page ORDER BY date_added DESC LIMIT :perPage OFFSET :blogOffset'; $stmt = $pdo->prepare($sql); // Prepare the query: $stmt->execute(['perPage' => $perPage, 'blogOffset' => $offset, 'page' => $page]); // Execute the query with the supplied data: return $stmt->fetchAll(PDO::FETCH_ASSOC); } Here's how to implement it: /* * Using pagination in order to have a nice looking * website page. */ if (isset($_GET['page']) && !empty($_GET['page'])) { $current_page = urldecode($_GET['page']); } else { $current_page = 1; } $per_page = 1; // Total number of records to be displayed: /* * Grab total records (rows) in a database table */ function totalRecords($pdo, $table, $page = 'blog') { $sql = "SELECT count(id) FROM " . $table . " WHERE page=:page"; $stmt = $pdo->prepare($sql); $stmt->execute([ 'page' => $page ]); return $stmt->fetchColumn(); } /* Total number of records that NEEDS to be displayed */ $total_count = totalRecords($pdo, 'cms'); /* calculate the offset */ $offset = $per_page * ($current_page - 1); /* calculate total pages to be displayed */ $total_pages = ceil($total_count / $per_page); /* Figure out the Pagination Links */ $links = links_function('index.php', $current_page, $total_pages); /* Finally, call for the data from the database table to display */ $cms = readData($pdo, 'cms', 'blog', $per_page, $offset); I don't know if it will help the OP any, but it should help others as well. 😉 I just want to add figuring out the Links isn't that hard to figure out and it shouldn't affect the pagination part, but it's pretty useless without it. I figure I can't do everything. 😉😃 Edited September 28, 2021 by Strider64 Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590476 Share on other sites More sharing options...
Barand Posted September 28, 2021 Share Posted September 28, 2021 @maviyazilim you are always outputting the last 10 in descending order. You should be outputting the results of the paginated query Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590484 Share on other sites More sharing options...
ginerjm Posted September 28, 2021 Share Posted September 28, 2021 I think my re-write has taken care of his lackluster logic. Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590485 Share on other sites More sharing options...
Barand Posted September 28, 2021 Share Posted September 28, 2021 Yeah, but he needed to have it pointed out in a picture where he went wrong. I can do that now he finally deigned to show the output code. Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590487 Share on other sites More sharing options...
maviyazilim Posted September 29, 2021 Author Share Posted September 29, 2021 barand. I got the above below. I deleted the query. this is the result. Fatal error: Uncaught TypeError: mysqli_fetch_assoc(): Argument #1 ($result) must be of type mysqli_result, string given in C:\xampp\htdocs\blog\orta.php:40 Stack trace: #0 C:\xampp\htdocs\blog\orta.php(40): mysqli_fetch_assoc('SELECT * FROM i...') #1 C:\xampp\htdocs\blog\index.php(4): include('C:\\xampp\\htdocs...') #2 {main} thrown in C:\xampp\htdocs\blog\orta.php on line 40 line 40 : while($goster=mysqli_fetch_assoc($sorgu)) { Quote Link to comment https://forums.phpfreaks.com/topic/313819-paging-is-not-happening/page/2/#findComment-1590505 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.