我尝试获取内容 ID,这是查询...
$getIDs = mysql_query("SELECT content_id FROM playlist_content WHERE playlist_id=".$rrow['playlist_id']."") or die(mysql_error());
while($row = mysql_fetch_array($getIDs)) {
$array[] = $row;
}
这是结果
Array
(
[0] => Array
(
[0] => 33
[content_id] => 33
)
[1] => Array
(
[0] => 13
[content_id] => 13
)
[2] => Array
(
[0] => 8
[content_id] => 8
)
)
现在必须从具有此 ID 的第二个表获取值 注意:ID = content_id
$result = mysql_query("SELECT SUM( length ) as total FROM content WHERE ID ...
并回显所有行的总和['length',这个ID在哪里 需要返回结果,例如 102 或 256 等...
或者有没有更好的方法来获取总和?
最佳答案
实际上,您可以通过连接两个表在单个查询中完成此操作,
SELECT a.content_id, SUM(b.length) TotalSum
FROM playlist_content a
INNER JOIN content b
ON a.content_id = b.ID
WHERE a.playlist_id = IDHERE
GROUP BY a.content_id
查询结果将为您提供每个 content_id
的 length
总和。
要进一步了解有关联接的更多知识,请访问以下链接:
关于php - ID 多的总值(value)总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16868873/