Skip to content

Instantly share code, notes, and snippets.

@abel-masila
Created July 10, 2017 19:59
Show Gist options
  • Save abel-masila/db1771ff3c7f944af3da71ee3f078692 to your computer and use it in GitHub Desktop.
Save abel-masila/db1771ff3c7f944af3da71ee3f078692 to your computer and use it in GitHub Desktop.
<div class="wrapper wrapper-content">
<?php
if(isset($_GET['page'])){
$page = $_GET['page'];
if($page== 1){
include("pages/mycars.php");
} else if($data['location'] == ''){
include('pages/additional_info.php');
}else{
//display reports
}
i
?>
</div>
<?php
//get all cars of the logged in user
$id = $data['id']; //super global var
$num_rec_per_page=3;
if (isset($_GET["view"])) { $view = $_GET["view"]; } else { $view=1; };
$start_from = ($view-1) * $num_rec_per_page;
$all_cars = mysqli_query($connection, "SELECT * FROM cars WHERE userid=$id LIMIT $start_from, $num_rec_per_page");
$count = mysqli_num_rows($all_cars);
?>
<div class="row">
<div class="col-xs-12 col-sm-12">
<nav class="services-pagination">
<ul class="pagination">
<?php
$result = mysqli_query($connection, "SELECT * FROM cars WHERE userid=$id");
$total_records = mysqli_num_rows($result);
$total_pages = ceil($total_records / $num_rec_per_page);
?>
<li class="">
<a href="?page=1">First Page</a>
</li>
<?php
for ($i=1; $i<=$total_pages; $i++) {
?>
<li class="">
<?php
echo "<a href='?page=1?view=".$i."'>".$i."</a> ";
};
?>
</li>
<?php
?>
<li class="">
<a href="?page=1&amp;view=<?php echo $total_pages?>">Last Page</a>
</li>
</ul>
</nav>
</div>
</div>
@sunriax
Copy link

sunriax commented Jul 10, 2017

Please use htmlentities if you get data from extern!!! Else injections into the php code are possible!
$page = htmlentities($_GET['page']);

That is also really important for mysql strings (mysql_real_escape_string())!!!

Ps.: I found it in the gist!

@abel-masila
Copy link
Author

Awesome @sunriax. Actually that code is not working. I can't get pagination to work in this case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment