我试图在会话中保留$ id值,以便可以在分页时有效地使用它...
if(empty($_GET["cat"])){
$session->message('<div class="error-msg">No product was selected.</div>');
redirect_to("view_all.php");
}else{
$id = $database->escape_value($_GET["cat"]);
$page = !empty($_GET['page']) ? (int)$_GET['page'] : 1;
$per_page = 50;
$sql = "SELECT COUNT(*) FROM products WHERE category='$id'";
$sql = $database->query($sql);
$sql = $database->fetch_array($sql);
$total_count = array_shift($sql);
$pagination = new Pagination($page, $per_page, $total_count);
$sql = "SELECT * FROM products WHERE category='$id'";
$sql .= " ORDER by id DESC";
$sql .= " LIMIT {$per_page} ";
$sql .= "OFFSET {$pagination->offset()}";
$result = Product::find_by_sql($sql);
}
答案 0 :(得分:0)
您不是应该首先使用以下命令启动会话:session_start()
吗?然后将其添加到$_SESSION
而不是$session
中。如果您将其设置为$session
,则与其他任何变量一样,但$_SESSION
是官方的PHP会话变量