I am making a page where there will be tables (each table is in a fieldset) with the option to edit or remove records. I added pagination incase the tables get too big for the page. Only problem is that (I am a beginner) when I go to next page, All the tables go to the next page. Is it possible to make pagination work per fieldset?
This is what I have so far: (Its Huge Code, I put only a part for 1 table)
Index:
<?php
include("pagination2.php");
?>
<div id="pagination">
<div id="pagiCount">
<html>
<head>
<nav>
<ul>
<li><a href="Index.php">Home</a>
<li><a href="Inventory.php">Inventory</a>
<li><a href="Categories.php">Categories</a>
<li><a href="Sales.php">Sales</a>
<li><a href="Customers.php">Customers</a></a>
<li><a href="Reports.php">Reports</a>
<li><a href="#top">Edit</a></a>
<li><a href="Remove.php">Remove</a></a>
</ul>
</nav>
</br></br></br></br>
<link rel="stylesheet" href="Styles.css">
</link>
</head>
<fieldset>
<?php
include_once('Connect2db.php');
if(isset($_POST['Categorie1'])) {
$Categorie = $_POST['Categorie1'];
if(mysql_query("INSERT INTO bcd VALUES('','$Categorie1')"))
echo "successful!";
else
echo "Please try again";
}
$res = mysql_query("SELECT * FROM bcd");
?>
<h1> Lijst met Categories..</h1>
<?php
while( $row = mysql_fetch_array($res) )
echo "$row[ID]. $row[Categorie1] <a href='Edit.php?edit=$row[ID]'>edit</a><br />";
?>
<br/>
<?php
if(isset($pages))
{
if($pages > 1)
{ if($cur_page > $num_links) ///////////to take to page 1 //////////
{ $dir = "first";
echo '<span id="prev"> <a href="'.$_SERVER['PHP_SELF'].'?page='.(1).'">'.$dir.'</a> </span>';
}
if($cur_page > 1)
{
$dir = "prev";
echo '<span id="prev"> <a href="'.$_SERVER['PHP_SELF'].'?page='.($cur_page-1).'">'.$dir.'</a> </span>';
}
for($x=$start ; $x<=$end ;$x++)
{
echo ($x == $cur_page) ? '<strong>'.$x.'</strong> ':'<a href="'.$_SERVER['PHP_SELF'].'?page='.$x.'">'.$x.'</a> ';
}
if($cur_page < $pages )
{ $dir = "next";
echo '<span id="next"> <a href="'.$_SERVER['PHP_SELF'].'?page='.($cur_page+1).'">'.$dir.'</a> </span>';
}
if($cur_page < ($pages-$num_links) )
{ $dir = "last";
echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.$pages.'">'.$dir.'</a> ';
}
}
}
?>
</div>
</div>
</fieldset>
<fieldset>
Pagination:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// select database
mysql_select_db("inventarisdb", $con); ////provide database name
$query = mysql_query("SELECT * FROM bcd");
$total_rows = mysql_num_rows($query);
$base_url = 'https://localhost/pagi/';
$per_page = 7; //number of results to shown per page
$num_links = 8; // how many links you want to show
$total_rows = $total_rows;
$cur_page = 1; // set default current page to 1
if(isset($_GET['page']))
{
$cur_page = $_GET['page'];
$cur_page = ($cur_page < 1)? 1 : $cur_page; //if page no. in url is less then 1 or -ve
}
$offset = ($cur_page-1)*$per_page; //setting offset
$pages = ceil($total_rows/$per_page); // no of page to be created
$start = (($cur_page - $num_links) > 0) ? ($cur_page - ($num_links - 1)) : 1;
$end = (($cur_page + $num_links) < $pages) ? ($cur_page + $num_links) : $pages;
$res = mysql_query("SELECT * FROM bcd LIMIT ".$per_page." OFFSET ".$offset);
mysql_close($con);
?>
Please tell me if pagination per fieldset is possible and if my method of trying to achieve this is the proper one. Links with tutorials or examples to achieve what I want are also welcome. Thank you in advanced!