skip to Main Content

Using RedBaeanPHP, I want the page to be updated and add + 1 to the "view".
Please help me, I don’t understand it very well.

$post_id = $_GET['post_id'];
$posts = R::load('posts', $post_id);

if (isset($_SESSION['recent_posts'])) {
    R::exec('UPDATE posts SET view = "view" + 1 WHERE id = $posts["id"]');
};

When a page is refreshed, it is not added to the database.

2

Answers


  1. Chosen as BEST ANSWER

    Thanks, already solved the problem

    $id = $posts['id'];
    $view = "UPDATE `posts` SET `view` = `view` + 1 WHERE `id`= $id";
    R::exec($view);
    

  2. Since you have already loaded the rquested post from the database (by doing $posts = R::load('posts', $post_id);) you could use the store method instead of R::exec.... So just use $posts->view++; and R::store($posts);

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search