My problem is that only the first page has pagination. The others are empty. I have tried to make it work but have not succeeded. Does anyone have an idea.
<?php
$datatable = "component_value"; // MySQL table name
$results_per_page = 10; // number of results per page
$foodid = $_SESSION['foodid'] ;
echo $foodid ;
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * $results_per_page;
$sql = "SELECT EUFDNAME, BESTLOC FROM $datatable WHERE FOODID = '".$_SESSION['foodid']."' ORDER BY EUFDNAME ASC LIMIT $start_from, ".$results_per_page;
$rs_result = $conn->query($sql);
$foodid = $_SESSION['foodid'] ;
?>
<table border="1" cellpadding="4">
<tr>
<td bgcolor="#CCCCCC"><strong>Livamedel</strong></td>
<td bgcolor="#CCCCCC"><strong>Innehåll</strong></td>
<?php
while($row = $rs_result->fetch_assoc()) {
?>
<tr>
<td><? echo $row["EUFDNAME"]; ?></td>
<td><? echo $row["BESTLOC"]; ?></td>
</tr>
<?php
};
?>
</table>
<?php
$sql = "SELECT COUNT(EUFDNAME) AS total FROM $datatable WHERE FOODID = '".$_SESSION['foodid']."'";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$total_pages = ceil($row["total"] / $results_per_page); // calculate total pages with results
for ($i=1; $i<=$total_pages; $i++) { // print links for all pages
echo "<a href='index.php?page=".$i."'";
if ($i==$page) echo " class='curPage'";
echo ">".$i."</a> ";
};
?>