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条)

报告相同问题?

悬赏问题

  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao