I have a php main page which includes other php pages in different div. I want to apply pagenation in one div and only load that div when the pages are selected. The problem is my output is not in the database and I am using the output of a console application that is I will have all the datas after the console application is executed. It is not possible for me to call the console app everytime the page is changed as it take more than 10 sec to execute it. I think I should use ajax for this but I am not sure where to use it. The main page uses ajax to display the div where the output is shown and where the pagenation is to be done. I am posting my code just to make it clear.
The main page:
<html>
<head>
<script type="text/javascript">
function myfunction()
{
$("#display").html('');
$("#retrieveimageform").ajaxForm(
{
target: '#display'
}).submit();
};
</script>
<title></title>
</head>
<body>
<div id="maindiv">
<div id="right">
<div id="grpbox">
<form action="retrieveimage1.php" method="post"
id="retrieveimageform">
<div id='type'>
<fieldset id="typefield" name="typebox">
<legend>
<label>
Type
</label>
</legend>
<p><input type="radio" id="shoes" name="cat" value="shoes"><label for="shoes">Shoes: </label></input><br/>
<input type="radio" id="dress" name="cat" value="dress"><label for="dress">Dress: </label></input><br/>
<input type="radio" id="handbag" name="cat" value="handbag"><label for="handbag">Handbag: </label></input></p>
</fieldset>
</div>
</div>
<div id="button">
<input type="submit" id="btnSearch" value="Search" class="button" onclick="myfunction()">
</div>
</form>
</div>
<div id="display"></div>
</div>
</div>.....
The retrieveimageform1.php where the output are displayed and which is displayed in the display div above.I want to do pagenation in this div whithout loading the whole page. The code below shows paging with page load but it is not suitable in my case so how can I use it to make paging wihtout page load.
<?php
$data=array();
session_start();
$start_time= microtime(true);
if (isset($_SESSION['img']))
{
$image=$_SESSION['img'];
if (isset($_POST['cat']))
{
if($_POST['cat']=='handbag')
{
$addr="/home/fashion/fashion_proj/handbagsfinal $image $cwt $fwt $swt $twt";
exec($addr,$data);
echo "<div id='tags'>";
echo ...................
}
echo "</div>";
echo "<fieldset id='outputfield' name='output' class='field_set'><legend><label>Similar items</label></legend>";
// find out how many rows are in the table
$numrows = 50;
// number of rows to show per page
$rowsperpage = 10;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$c=12*$currentpage; datas start from in first page 12
echo "<div id='imgdisplay'>";
....... echo datas to be dispalyed
/****** build the pagination links ******/
// range of num links to show
$range = 3;
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} // end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
} else {
// make it a link
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
// echo forward link for lastpage
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
/****** end build pagination links ******/
echo "</fieldset>";
..........
Where should I apply ajax in the main page or the retreive page any helpful links,tutorail or suggestions?