dtamho6404 2018-01-08 14:14
浏览 58
已采纳

显示计数查询中的单个数据(mySQL / php)

I have a database called 'Telcel' and a table called 'calls' columns in my table are id,call_from,call_to,date_time,duration,network,cost,status

I have the following code:

        $conn = mysqli_connect("localhost", "daven", "H3x^g0n", "Telcel");
        $query = "SELECT id, COUNT(id), call_from,ROUND(SUM(cost), 2) FROM calls GROUP BY call_from ORDER BY COUNT(id) DESC;";
        $result = mysqli_query($conn, $query);

        while($row = mysqli_fetch_assoc($result))
        {
            echo '
                    <tr>
                        <td><a href="total.php">'. $row['call_from'] .'</a></td>
                        <td>'. $row['COUNT(id)'] .'</td>
                        <td>'. $row['ROUND(SUM(cost), 2)'] .'</td>
                    </tr>
                 ';
        }

which returns for example:

Call From   Calls   Cost
Shannon     10      50.2
Tom         3       7.6

I'd like when a name is selected to display all the calls, duration for each call and cost of each call made by the selected caller on the next page,So if Tom is selected display all the relevant information for Tom only, and if Shannon is selected same thing etc. Thank you.

  • 写回答

1条回答 默认 最新

  • duanduoding2238 2018-01-08 14:53
    关注

    You can sent GET requrest with url like total.php?call_from=Tom
    So, you need to generate a href link with call from name :

    while($row = mysqli_fetch_assoc($result)) {
        <td><a href="total.php?call_from='.$row["call_from"].'">'. $row['call_from'] .'</a></td>
        ...
    }
    

    And total.php use $_GET["call_from"] for receiving id from url to use in query :

    $call_from = $_GET["call_from"];
    $query = "SELECT * FROM calls WHERE call_from = ". $call_from;
    ... //Display the table
    

    Hope this help :)

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

报告相同问题?

悬赏问题

  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 这个公式写进SIMULINK中的function模块的代码中应该是什么样的
  • ¥15 javaweb登陆的网页为什么不能正确连接查询数据库
  • ¥15 数学建模数学建模需要
  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥20 nao机器人语音识别问题
  • ¥15 怎么生成确定数目的泊松点过程
  • ¥15 layui数据表格多次重载的数据覆盖问题
  • ¥15 python点云生成mesh精度不够怎么办