我正在显示数据库中的一些图像。首先我显示所有图像然后如果用户点击按钮我想用查询过滤它。
<div class="align_center gallery">
<?php
include "anj.php";
if($_GET['submit']){
$sql = 'SELECT * FROM new_photos WHERE weight BETWEEN 10 AND 15';
anjaan($sql);
}
else{
$sql='select * from new_photos';
anjaan($sql); }
?>
</div>
<div class=" align_center ">
<div class=" col-md-12 pagination gallery">
<?php
echo $paginationctrl;
?>
</div>
</div>
当我点击按钮
<form method="GET" >
<input type="Submit" name="submit" value="submit">
</form>
然后它显示来自第一个查询的图像和页面(如果声明)
"'SELECT * FROM new_photos WHERE weight BETWEEN 10 AND 15';"
它显示了此查询所具有的确切页面,但是当我点击第二页时,它显示来自else语句的内容
"'SELECT * FROM new_photos ";
我希望当我点击提交按钮后单击第二页时,它应显示第一次查询的图像。
分页代码是
global $paginationctrl;
$paginationctrl='';
if($last !=1){
if($pagenum>1){
$previous = $pagenum-1;
$paginationctrl .='<a href="'.$_SERVER['PHP_SELF'].'?pn='.$previous.'">Pr</a>'.' ';
for($i = $pagenum-3 ;$i<$pagenum;$i++){
if($i>0){
$paginationctrl .='<a class="active" href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a>'.' ';
}
}
}
$paginationctrl .=''.$pagenum.' ' ;
for($i = $pagenum+1 ;$i<$last;$i++){
$paginationctrl .='<a class="active" href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a>'.' ';
if($i>=$pagenum+4){
break;
}
}
if($pagenum != $last){
$next =$pagenum+1;
$paginationctrl .=' <a href="'.$_SERVER['PHP_SELF'].'?pn='.$next.'">Next</a>';
}
}
答案 0 :(得分:0)
<?php
session_start(); // this have to be called before any output
if(isset($_GET['sort'])){
$_SESSION['sort'] = $_GET['sort'] == 'true';
}
if(isset($_SESSION['sort']) && $_SESSION['sort']){
echo 'sorted<br />';
}else{
echo 'unsorted<br />';
}
?>
<!-- link get method -->
<a href="?sort=true">sorted</a><br />
<a href="?sort=false">unsorted</a>
<!-- form get method -->
<form method="GET">
<select name="sort">
<option value="true">sorted</option>
<option value="false">unsorted</option>
</select>
<input type="submit" name="submit" value="submit">
</form>
你的代码中的:
<?php
if(isset($_GET['sort'])){
$_SESSION['sort'] = $_GET['sort'] == 'true';
}
include "anj.php";
if(isset($_SESSION['sort']) && $_SESSION['sort']){
$sql = 'SELECT * FROM new_photos WHERE weight BETWEEN 10 AND 15';
anjaan($sql);
} else {
$sql = 'select * from new_photos';
anjaan($sql);
}
?>
从上面选择链接或表单,不要忘记将session_start();
放在文件的顶部