-2

I am trying to retain the $id value in a session so that i can use it effectively with the pagination...

  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);   
    }
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
sanmexm
  • 1
  • 4

1 Answers1

0

Shouldn't you start the session first with the command: session_start()? Then add it to $_SESSION instead of $session. If you put it as $session, it is just like any other variable but $_SESSION is the official PHP session variable

zS1L3NT
  • 461
  • 5
  • 14