简体   繁体   中英

fetch data from mongodb and show it in html table

I have data in this format:

{
    "jobname" : "2018_09_27_test123_0",
    "totalcalls" : 1836.0,
    "success" : 3.0,
    "fail" : 1833.0,
    "failureReasons" : [ 
        {
            "reason" : "Unavailable",
            "count" : 53.0
        }, 
        {
            "reason" : "SIP_RedirectFailed",
            "count" : 1698.0
        }, 
        {
            "reason" : "Ringingtimeout",
            "count" : 64.0
        }, 
        {
            "reason" : "Misc",
            "count" : 10.0
        }, 
        {
            "reason" : "UnallocatedNumber",
            "count" : 7.0
        }, 
        {
            "reason" : "SIP_AckNotReceived",
            "count" : 1.0
        }
    ]
}

I want to show this data in table format. I was able to show jobname, totalcalls, success and fail but I was unable to show failure reason. I want to show failure reason count in the table.

foreach ($cursor as $venue) {
    echo "<tr>"; 
    echo "<td>" . $venue['jobname'] . "</td>"; 
    echo "<td>" . $venue['totalcalls'] . "</td>"; 
    echo "<td>" . $venue['success'] . "</td>"; 
    echo "<td>" . $venue['fail'] . "</td>"; 
}

but I am finding problem to read failurereasons. I want to count the reason and put in the table:

<td>Ringingtimeout</td>
<td>UnallocatedNumber</td>
<td>SIP_AckNotReceived</td>`

To count the failure reasons you can use count($venue['failureReasons']) .

Also to display all the reasons like below

foreach ($c as $venue['fail']) {
    echo  $c['reason']
}

Also, you want to display all the reasons on the same table you have to use

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM