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
Thanks, already solved the problem
Since you have already loaded the rquested post from the database (by doing
$posts = R::load('posts', $post_id);
) you could use thestore
method instead ofR::exec...
. So just use$posts->view++;
andR::store($posts);