douqiao7188 2013-07-03 23:07
浏览 44
已采纳

COUNT(*)AS发生,php如何捕获每次出现的值

If i run the following code in phpmyadmin it shows a column with the total occurrences for each friendly_name but when i run it in php and echo out the table i dont know how to pull the value of occurences and add it to my table?

SELECT *, COUNT(*) AS occurrences
FROM my_reports 
GROUP BY friendly_name
HAVING count(*) > 1
ORDER BY occurrences DESC

This is the code im echoing out and i know its probably incredibly simple but i havent tried this before so i dont know where to start

while ($row = mysql_fetch_array($sel_rs))
        {
        $hud_id = $row['hud_id'];
        $friendly_name = $row['friendly_name'];     

            echo '<tr><td>'.$hud_id.'</td>';

            echo '<td>'. $friendly_name.'</td>';
            echo '<td>'. what do i put here to show occurances for each.'</td></tr>';
        }

echo "</tbody></table>"; 
  • 写回答

1条回答 默认 最新

  • dou6577 2013-07-03 23:08
    关注

    Simple... $occurrences = $row['occurrences'];

    PS: You should ditch mysql_* functions and learn MySQLi at the very least, or PDO.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本