dougu5847 2014-10-08 13:08
浏览 60

php代码获取总和值并显示总和值的最大值

table name--- voter

field name voter

type integer

I am selecting distinct values from this table, getting sum of voter field, and echoing this field in a loop.

I need to take the above summed value result in variable and display the maximum value from this sum field. How can I accomplish this?

Here's my code:

<?php       
        $party = $rowco['partyname'];   
        $district = $rowco['district']; 
        $constituency = $rowco['constituency'];     
        $sqlvotes = "SELECT SUM(votes) AS vote,constituency FROM voter_count where state = '$state' AND partyname = '$party' AND district = '$district' AND constituency = '$constituency'";    
        $resultvotes = mysql_query($sqlvotes);  
        while($rowvotes = mysql_fetch_array($resultvotes,MYSQL_ASSOC))
        {               
        ?>   
         <th><?php echo $rowvotes['vote']; ?></th>  
          <th><?php echo $rowvotes['constituency']; ?></th>       
    </tr>
    <?php }  ?>
  • 写回答

1条回答 默认 最新

  • dongnvwang8591 2014-10-08 13:12
    关注

    Simple as that :

    $max = -1;
    while($rowvotes = mysql_fetch_array($resultvotes,MYSQL_ASSOC))
    {               
        if ($rowvotes['vote'] > $max) $max = $rowvotes['vote'];
        ?>   
        <th><?php echo $rowvotes['vote']; ?></th>  
        <th><?php echo $rowvotes['constituency']; ?></th>       
        </tr>
        <?php 
    } 
    
    echo "Max value : $max";
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作