我正在显示数据库中的图片。我可以选择让用户缩短一些图像作为输入。当用户输入一些数字时,照片将根据输入短。
<?php session_start();?>
<?php
include "script/db_script.php";
if(isset($_GET['value1']) && isset($_GET['value2'])){
$value1 = $_GET['value1'];
$value2 = $_GET['value2'];
$_SESSION['value1'] = $_GET['value1'] ;
$_SESSION['value2'] = $_GET['value2'];
}
if(isset($_SESSION['value1']) && $_SESSION['value1']&&
isset($_SESSION['value2'])&& $_SESSION['value2'] ){
$sql = "SELECT * FROM new_photos WHERE weight BETWEEN
$value1 AND $value2";
anjaan($sql);
echo "<p>Showing images from $value1 gm to $value2 gm</p>";
}
else{
$sql='select * from new_photos';
anjaan($sql);
echo "<p>Showing all images </p>";}
?>
我的表格是
<form method="GET">
From <input style="width: 50px;" name="value1" = type="number"<br>
To <input style="width: 50px;" name="value2"type="number"><br>
<input type="submit" name="submit" value="submit">
</form>
我的问题是当我点击下一页的分页表格变量而不是设置为会话时。
此代码工作正常
<?php
include "script/db_script.php";
if(isset($_GET['sort'])){
$_SESSION['sort'] = $_GET['sort'] == '5_15';
$_SESSION['sort1'] = $_GET['sort'] == '1_10';
}
if(isset($_SESSION['sort']) && $_SESSION['sort']){
$sql = 'SELECT * FROM new_photos WHERE weight BETWEEN 5 AND 15';
anjaan($sql);
echo "<p>Showing images with 5gm to 15gm</p>";
}
elseif(isset($_SESSION['sort']) && $_SESSION['sort1']){
$sql = 'SELECT * FROM new_photos WHERE weight BETWEEN 1 AND 10';
anjaan($sql);
echo "<p>Showing images with 1gm to 10gm</p>";
}
else{
$sql='select * from new_photos';
anjaan($sql);
echo "<p>Showing all images </p>";}
?>
表格
<form method="GET">
<select name="sort">
<option value="all">All</option>
<option value="1_10">1 gm to 10 gm</option>
<option value="5_15">5 gm to 15gm</option>
</select>
<input type="submit" name="submit" value="submit">
</form>
答案 0 :(得分:0)
在使用会话之前,您需要先打开会话:
在任何HTML添加之前的页面顶部:
<?php
// Start the session
session_start();
?>