Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 获取大数据,然后从中计数_Php_Mysql - Fatal编程技术网

Php 获取大数据,然后从中计数

Php 获取大数据,然后从中计数,php,mysql,Php,Mysql,我想知道,如果我从MySQL的所有不同表中获取大量数据,那么如何计算特定行的值总数 $thedata= mysql_query("select comment,Date,hits,abc,xyz from fk_views where onid='$thepicid'"); 我想计算此查询获取的总点击数。 通常我们都喜欢 mysql_num_rows($thedata); 此查询将告诉您获取的数据总数,而不是获取的点击总数。正如@Barmar所建议的,您可能希望使用SUM,但是,hits字段

我想知道,如果我从MySQL的所有不同表中获取大量数据,那么如何计算特定行的值总数

$thedata= mysql_query("select comment,Date,hits,abc,xyz from fk_views where onid='$thepicid'");
我想计算此查询获取的总点击数。 通常我们都喜欢

mysql_num_rows($thedata);

此查询将告诉您获取的数据总数,而不是获取的点击总数。

正如@Barmar所建议的,您可能希望使用
SUM
,但是,
hits
字段本身不正是返回您想要的结果吗?该列如何递增以及如何递增?

您可以尝试以下方法:

<?php
// Create connection
$con=mysqli_connect("localhost","user","password","database");

// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$thedata= mysqli_query($con, "select comment,Date,hits,abc,xyz from fk_views where onid='$thepicid'");

$row_count = mysqli_num_rows($thedata);
echo $row_count;
?>
$thedata= mysqli_query("select SUM(hits) as hitcount,comment,Date,hits,abc,xyz from fk_views where onid='$thepicid'");

这将在同一个查询中获得总和(点击数)。

点击数是什么意思?另外,
mysql
扩展也不推荐使用。迁移到
mysqli
扩展。你是否在问如何获得
SUM(hits)
?除了使用不同的MySQL API,这与他编写的有什么不同?但这不会得到与他原始代码相同的答案吗?它是如何解决他的问题的?是的。。你说得对。。也许他是想得到命中数的总和,为了得到它,我必须纠正一个不同的代码,比如$thedata=mysql\u查询(“从fk\u视图中选择命中数,其中onid='$thepicid');mysql\u num\u行($thedata);你能再详细一点吗?因为
从fk_视图中选择SUM(hits),其中noid=$thepicid
我认为可以解决您的问题,您尝试过吗?