Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/08/2022 in all areas

  1. after searching and experimenting, both of the following methods will convert a dynamic unicode code point (the f192, f57f, ... values) to utf8 - $icon = IntlChar::chr(hexdec($c_icon)); // or $icon = mb_chr(hexdec($c_icon), 'UTF-8'); replace the $c_icon with $p_icon, or the literal 'f57f' in the else: branch. this requires removing the JSON_UNESCAPED_UNICODE flag in the json_encode() call.
    1 point
  2. Or do it the easy way code $res = $pdo->query("SELECT created_at FROM test_b ORDER BY created_at DESC "); $today = new DateTime('now'); foreach ($res as $row) { $dt = new DateTime($row['created_at']); $diff = $dt->diff($today)->format("%y years -- %m months -- %d days"); echo "{$row['created_at']} | $diff <br>"; } output 2020-10-15 00:00:00 | 1 years -- 9 months -- 22 days 2020-09-06 00:00:00 | 1 years -- 11 months -- 0 days 2019-04-09 00:00:00 | 3 years -- 3 months -- 28 days 2019-03-08 00:00:00 | 3 years -- 4 months -- 29 days 2018-06-06 00:00:00 | 4 years -- 2 months -- 0 days 2018-06-04 00:00:00 | 4 years -- 2 months -- 2 days 2018-05-27 00:00:00 | 4 years -- 2 months -- 10 days 2018-05-15 00:00:00 | 4 years -- 2 months -- 22 days 2018-02-03 00:00:00 | 4 years -- 6 months -- 3 days 2018-01-05 00:00:00 | 4 years -- 7 months -- 1 days
    1 point
  3. FYI - my preferred method is not to use links with query strings but to add a hidden "page" field to the search form. When the pagination buttons are clicked they update the hdiden field with their page number and resubmit the form. Example (The table used is "pupil" table from my sql tutorial) <?php include 'db_inc.php'; // creates pdo connection $pdo = pdoConnect('jointute'); // use your own $searches_per_page = 5; $search = $_GET['search'] ?? ''; // set defaukt values $page = $_GET['page'] ?? 1; // // // Record count // $res = $pdo->prepare("SELECT COUNT(*) FROM pupil WHERE lname LIKE ? "); $res->execute(["%{$search}%"]); $number_of_pages = ceil($res->fetchColumn()/$searches_per_page); $prev = $page > 1 ? $page - 1 : 1; $next = $page < $number_of_pages ? $page + 1 : $number_of_pages; $start = max(1, $page - 2); $end = min($number_of_pages, $page + 2); // // Get data for display // $res = $pdo->prepare("SELECT fname , lname , classid , dob , timestampdiff(YEAR, dob, CURDATE()) as age FROM pupil WHERE lname LIKE ? ORDER BY lname, fname LIMIT ?,? "); $res->execute(["%{$search}%", ($page-1)*$searches_per_page, $searches_per_page ]); $pupils = ''; foreach ($res as $row) { $pupils .= "<tr><td>" . join("</td><td>", $row) . "</td></tr>" ; } ?> <!DOCTYPE html> <html lang='en'> <head> <title>Search example</title> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script type='text/javascript'> $().ready (function() { $(".paging").click( function() { let page = $(this).val() $("#page").val(page) // set page no in hidden form field $("#searchform").submit() // resubmit the form }) }) </script> <style type='text/css'> body { background-color: black; color: white; } td , th { padding: 4px; } </style> </head> <body> <form id='searchform'> Search for <input type='text' name='search' value="<?=$search?>"> <input type='hidden' name='page' id='page' value='<?=$page?>'> <input type='submit' value='Search'> </form> <?php if ($number_of_pages > 1) { echo "<br><br><button class='paging' value='$prev'>&lt;</button> "; for ($p = $start; $p <= $end; $p++) { echo "<button class='paging' value='$p'>$p</button> "; } echo "<button class='paging' value='$next'>&gt;</button>"; } ?> <br><br> <table border='1'> <tr><th>First Name</th><th>Last Name</th><th>Class</th><th>DOB</th><th>Student Age</th></tr> <?=$pupils?> </table> </body> </html>
    1 point
This leaderboard is set to New York/GMT-05:00
×
×
  • 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.