Postingan

Menampilkan postingan dengan label php

StackOverflow Like Pagination

Gambar
Some while ago, I built a pagination system in PHP to display a long list of pagination links. The pagination system showed at most 5 links at a time and additional links were represented by ellipsis (...). However, I was not able to deal with certain edge cases, so I drew some inspiration from the pagination system used on StackOverflow to tackle them. This is what the end result looked like: The first and last page links are always visible The previous and next page links (numeric ones) are always visible At most n page links excluding first and last page links are visible; rest are represented by ellipsis The pagination for first and last n - 1 pages is handled a bit differently Complete PHP source code below. DEMO DISINI Pagination Function <?php /** * Displays pagination links based on given parameters * * @param int $currentPage - current page * @param int $itemCount - number of items to paginate, used to calculate total number of pages * @param int $items...

How to Fix the Typical "My PHP Script Does Not Work" Problem

Gambar
A PHP script that "does not work" because of an error will emit error messages such as "use of undefined variable", "an error in MySQL query", "permission denied", "parse error", etc. If you do not see an error when you should, it could mean that PHP is configured to suppress errors; a common practice in production environments. Developers who use AMP stacks unknowingly have PHP setup this way, and when they run into "does not work" problems and see no errors, they start asking silly questions. The environment in which you develop code must be setup differently. Here is what you need to do in order to make PHP more verbose about errors. display_errors = On The most common reason for not seeing an error is that that the display_errors » setting is off. Set its value to on so that the PHP displays the errors as part of the output. error_reporting = E_ALL | E_STRICT The error_reporting » setting determines t...