douzong3599 2014-05-16 14:17
浏览 40
已采纳

从特定模式中查找并汇总mysql字段

I have in a mysql table the number of downloads for a specific file.

I use the following code to fetch the number of downloads:

<?php $debname = 'com.dev.package_1.0-1_iphoneos-arm.deb'; ?>  

<?PHP include("../../config.php");
$query = "SELECT stats FROM download WHERE filename =  '".$debname."'";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
echo $row[0];
}
?>

Sometimes, i update the packages and the name of the new package will be changed, for example: com.dev.package_2.1-1_iphoneos-arm.deb

This will then make the page display the counts of the new package which are reset to 0

Therefore, I'm trying to find a way to get the total number of downloads for all the versions

For example:

filename                                |     stats
________________________________________|_________________
com.dev.package_1.0-1_iphoneos-arm.deb  |       25
com.dev.package_2.1-1_iphoneos-arm.deb  |       2
________________________________________|_________________
Total Downloads of com.dev.package      |       27

So I want to display on my page the sum of the 2 file which is 27

  • 写回答

2条回答 默认 最新

  • douyi1939 2014-05-16 14:20
    关注

    EDIT:

    $query = "SELECT sum(stats) AS sum FROM download WHERE filename LIKE '%com.dev.package%'";
    
    
    echo $row[sum];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?