我正在尝试将配置文件viewcount添加到mysql表中,并在刷新页面上或每次有人访问其配置文件时用php更新它。
我正在使用此代码:
$username = $_GET['user'];
$query = $connect->query("SELECT * FROM `users` WHERE `email` = '". $_SESSION['email'] ."'");
$u = $query->fetch_assoc();
$query = $connect->query("SELECT * FROM `users` WHERE `username` = '". $username ."'");
$r = $query->fetch_assoc();
$profile = $connect->query("SELECT * FROM `users.profiles` WHERE `user_id` = '". $r['id'] ."'");
$p = $profile->fetch_assoc();
$follows = $connect->query("SELECT * FROM `users.follows` WHERE `follow_id` = '". $r['id'] ."'");
$following = $connect->query("SELECT * FROM `users.follows` WHERE `user_id` = '". $u['id'] ."' AND `follow_id` = '". $r['id'] ."'");
//这是计数代码
$viewc = $r['viewcount'] + 1;
$alterview = $connect->query("UPDATE `users.profiles` SET `viewcount` = '". $viewc ."' WHERE `id` = '". $p['id'] ."'");
我不确定我要去哪里错,我需要它来更新user.profiles表的viewcount列中的+1计数。
任何帮助将不胜感激的家伙!
最佳答案
$ viewc = $ p ['viewcount'] + 1;
$ alterview = $ connect-> query(“ UPDATE users.profiles
SET viewcount
='”。$ viewc。“'WHERE id
='”。$ r ['id']。“'”);
这很奏效,谢谢大家。