我有一个 php 主页,其中包含不同 div 中的其他 php 页面。我想在一个 div 中应用分页,并且仅在选择页面时加载该 div。问题是我的输出不在数据库中,我正在使用控制台应用程序的输出,即在控制台应用程序执行后我将拥有所有数据。每次更改页面时,我都无法调用控制台应用程序,因为执行它需要 10 多秒。我想我应该为此使用 ajax,但我不确定在哪里使用它。主页使用 ajax 来显示显示输出的 div 以及要在哪里进行分页。我发布我的代码只是为了说明清楚。
主页面:
<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>.....
显示输出的retrieveimageform1.php,显示在上面的显示div中。我想在这个div中进行分页而不加载整个页面。下面的代码显示了页面加载的分页,但它不适合我的情况,所以我如何使用它来进行页面加载时的分页。
<?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>";
..........
我应该在主页或检索页面的哪里应用 ajax 任何有用的链接、教程或建议?