总喜欢的人数 [英] Total number of likes

查看:99
本文介绍了总喜欢的人数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一下喜欢的总数,但我不知道怎么能让这个来检索表的内容

Hi, I would like to write, the total number of likes, but I don't know how I can make this to retrieve the contents of the table

<?php
try
{
$user = 'root';
$pass = '';
$PDO = new PDO('mysql:host=localhost;dbname=mike', $user, $pass);
$PDO->exec("set names utf8");
$query = "SELECT SUM(likes) as test FROM news WHERE autor=".$_SESSION['id']."";

$c_query = $PDO->prepare($query;
$c_query->execute();
$results = $c_query->fetch(PDO::FETCH_ASSOC);

    if($results)
    {
        echo "Total number of likes: ".$f_test = $results['test'];
    }
}
catch(PDOException $e)
{
echo "Error: " .$e;
}
?>





我的尝试:



with COUNT()并使用多个查询



What I have tried:

with COUNT() and use multiple query

推荐答案

user = ' root';
user = 'root';


pass = ' ' ;
pass = '';


PDO = new PDO(' mysql:host = localhost; dbname = mike'
PDO = new PDO('mysql:host=localhost;dbname=mike',


这篇关于总喜欢的人数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆