Search
 
SCRIPT & CODE EXAMPLE
 

PHP

pagination php mysql

<?php

// insert your mysql connection code here

$perPage = 10;
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$startAt = $perPage * ($page - 1);

$query = "SELECT COUNT(*) as total FROM redirect
WHERE user_id = '".$_SESSION['user_id']."'";
$r = mysql_fetch_assoc(mysql_query($query));

$totalPages = ceil($r['total'] / $perPage);

$links = "";
for ($i = 1; $i <= $totalPages; $i++) {
  $links .= ($i != $page ) 
            ? "<a href='index.php?page=$i'>Page $i</a> "
            : "$page ";
}


$r = mysql_query($query);

$query = "SELECT * FROM 'redirect'
WHERE 'user_id'= ''.$_SESSION['user_id'].' ' 
ORDER BY 'timestamp' LIMIT $startAt, $perPage";

$r = mysql_query($query);

// display results here the way you want

echo $links; // show links to other pages
Comment

PREVIOUS NEXT
Code Example
Php :: laravel upload base64 image 
Php :: bindparam php 
Php :: fetch method and class in codeigniter 
Php :: php fetch mysql result as variable 
Php :: check if string contains substring php 8 
Php :: laravel eloquent get specific columns using with function 
Php :: Group by not working - Laravel 
Php :: Install Older Version of Laravel using Composer 
Php :: how to get a sum of a column in lravel 
Php :: General error: 1390 Prepared statement contains too many placeholders 
Php :: laravel return response view 
Php :: php concatenate string 
Php :: laravel model update table 
Php :: how to create shortcode with php 
Php :: php check if string contains url 
Php :: composer remove phpmailer 
Php :: php foreac 
Php :: wordpress disable block styles 
Php :: php define multiple variables as 0 
Php :: valid image extensions in php 
Php :: php check if multiple inputs are empty 
Php :: laravel update all relations 
Php :: convert array into , separated string in php 
Php :: query relationships laravel and select some columns 
Php :: how to enable pretty url in yii2 
Php :: php artisan route list does not show all my routes 
Php :: append data in csv file php 
Php :: json to html php table 
Php :: E: Unable to locate package php7.2-fpm 
Php :: How do I get current taxonomy "term id" on wordpress? 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =