Skip to content

Instantly share code, notes, and snippets.

Created February 17, 2018 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c00d1c8429114ecd49911dc81b6b855e to your computer and use it in GitHub Desktop.
Save anonymous/c00d1c8429114ecd49911dc81b6b855e to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = "";
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'register';
$connection = mysql_select_db($dbname);
$limit = 2;
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * $limit;
$sql = "SELECT * FROM tblproduct ORDER BY name ASC LIMIT $start_from, $limit";
$rs_result = mysql_query ($sql);
?>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>title</th>
<th>body</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysql_fetch_assoc($rs_result)) {
echo $row['name']; //for testing & this one is working but below it is not working
?>
<tr>
<td><? echo $row['name']; ?></td>
<td><? echo $row['price']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
$sql = "SELECT COUNT(id) FROM tblproduct";
$rs_result = mysql_query($sql);
$row = mysql_fetch_row($rs_result);
$total_records = $row[0];
$total_pages = ceil($total_records / $limit);
$pagLink = "<div class='pagination'>";
for ($i=1; $i<=$total_pages; $i++) {
$pagLink .= "<a href='pagination.php?page=".$i."'>".$i."</a>";
};
echo $pagLink . "</div>";
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment