【问题标题】:How to extract these values in PHP and show it in a table format? [closed]如何在 PHP 中提取这些值并以表格格式显示? [关闭]
【发布时间】:2014-11-03 16:12:57
【问题描述】:

如何将上述值显示为分页、排序和搜索选项?

stdClass 对象 ( [totalcdrcount] => 11 [cdrs] => 数组 ( [0] => 标准类对象 ( [通话日期] => 2014-10-31T16:02:38+05:30 [源] => 1111 [日期] => 1978 [频道] => SIP/1111-0000000f [dstchannel] => SIP/1978-00000010 [处置] => 已回答 [唯一] => 1414751558.15 [持续时间] => 511 [账单] => 508 [帐户代码] => )

            [1] => stdClass Object
                (
                    [calldate] => 2014-10-31T16:02:22+05:30
                    [src] => 1111
                    [dst] => 1111
                    [channel] => SIP/1111-0000000e
                    [dstchannel] => 
                    [disposition] => ANSWERED
                    [uniqueid] => 1414751542.14
                    [duration] => 13
                    [billsec] => 13
                    [accountcode] => 
                )

            [2] => stdClass Object
                (
                    [calldate] => 2014-10-31T15:33:22+05:30
                    [src] => 1111
                    [dst] => 1978
                    [channel] => SIP/1111-0000000c
                    [dstchannel] => SIP/1978-0000000d
                    [disposition] => ANSWERED
                    [uniqueid] => 1414749802.12
                    [duration] => 1730
                    [billsec] => 1722
                    [accountcode] => 
                )

            [3] => stdClass Object
                (
                    [calldate] => 2014-10-31T15:31:18+05:30
                    [src] => 1978
                    [dst] => 1111
                    [channel] => SIP/1978-0000000a
                    [dstchannel] => SIP/1111-0000000b
                    [disposition] => ANSWERED
                    [uniqueid] => 1414749678.10
                    [duration] => 117
                    [billsec] => 110
                    [accountcode] => 
                )

            [4] => stdClass Object
                (
                    [calldate] => 2014-10-31T15:31:04+05:30
                    [src] => 1111
                    [dst] => 1978
                    [channel] => SIP/1111-00000009
                    [dstchannel] => 
                    [disposition] => ANSWERED
                    [uniqueid] => 1414749664.9
                    [duration] => 10
                    [billsec] => 10
                    [accountcode] => 
                )

            [5] => stdClass Object
                (
                    [calldate] => 2014-10-31T15:30:30+05:30
                    [src] => 1978
                    [dst] => 1111
                    [channel] => SIP/1978-00000007
                    [dstchannel] => SIP/1111-00000008
                    [disposition] => ANSWERED
                    [uniqueid] => 1414749630.7
                    [duration] => 28
                    [billsec] => 21
                    [accountcode] => 
                )

            [6] => stdClass Object
                (
                    [calldate] => 2014-10-31T15:30:11+05:30
                    [src] => 1111
                    [dst] => 1978
                    [channel] => SIP/1111-00000005
                    [dstchannel] => SIP/1978-00000006
                    [disposition] => NO ANSWER
                    [uniqueid] => 1414749611.5
                    [duration] => 4
                    [billsec] => 0
                    [accountcode] => 
                )

            [7] => stdClass Object
                (
                    [calldate] => 2014-10-31T15:29:24+05:30
                    [src] => 1111
                    [dst] => 1978
                    [channel] => SIP/1111-00000004
                    [dstchannel] => 
                    [disposition] => ANSWERED
                    [uniqueid] => 1414749564.4
                    [duration] => 17
                    [billsec] => 17
                    [accountcode] => 
                )

            [8] => stdClass Object
                (
                    [calldate] => 2014-10-31T15:28:36+05:30
                    [src] => 1978
                    [dst] => 1111
                    [channel] => SIP/1978-00000002
                    [dstchannel] => SIP/1111-00000003
                    [disposition] => ANSWERED
                    [uniqueid] => 1414749516.2
                    [duration] => 43
                    [billsec] => 39
                    [accountcode] => 
                )

            [9] => stdClass Object
                (
                    [calldate] => 2014-10-31T15:19:18+05:30
                    [src] => 1978
                    [dst] => *97
                    [channel] => SIP/1978-00000001
                    [dstchannel] => 
                    [disposition] => ANSWERED
                    [uniqueid] => 1414748958.1
                    [duration] => 25
                    [billsec] => 25
                    [accountcode] => 
                )

            [10] => stdClass Object
                (
                    [calldate] => 2014-10-31T15:18:42+05:30
                    [src] => 1978
                    [dst] => *79
                    [channel] => SIP/1978-00000000
                    [dstchannel] => 
                    [disposition] => ANSWERED
                    [uniqueid] => 1414748922.0
                    [duration] => 4
                    [billsec] => 4
                    [accountcode] => 
                )

        )

)

如何将上述值显示为分页、排序和搜索选项?

【问题讨论】:

标签: php stdclass


【解决方案1】:

只需遍历它们并输出您的表格...

<?php
if ($response->totalcdrcount > 0) {
   $fields = array();
   foreach ($response->cdrs[0] as $field => $value) {
      $fields[] = $field;
   }
}

?>

<table>
  <thead>
    <tr>
      <?php foreach ($fields as $field): ?>
      <th><?php echo $field ?></th>
      <?php endforeach; ?>
    </tr>
  </thead>
  <tbody>
  <?php foreach ($response->cdrs as $cdr): ?>
    <tr>
      <?php foreach ($fields as $field): ?>
        <td><?php echo isset($cdr->$field) ? $cdr->$field : '&nbsp;' ?></td>
      <?php endforeach ?>
    </tr>
  <?php endforeach; ?>
  </tbody>
</table>

【讨论】:

  • 如何将上述值显示为页面、排序和搜索选项?
【解决方案2】:

我认为你需要这样的东西:

<table>
    <?php
    foreach ($object->crds as $Card) {
        ?>
        <tr>
            <td><?php echo $Card->calldate; ?></td>
            <td><?php echo $Card->src; ?></td>
            <td><?php echo $Card->dst; ?></td>
            <td><?php echo $Card->channel; ?></td>
            <td><?php echo $Card->dstchannel; ?></td>
            <td><?php echo $Card->disposition; ?></td>
            <td><?php echo $Card->uniqueid; ?></td>
            <td><?php echo $Card->duration; ?></td>
            <td><?php echo $Card->billsec; ?></td>
            <td><?php echo $Card->accountcode; ?></td>
        </tr>
        <?php
    }
    ?>
</table>

【讨论】:

    【解决方案3】:

    很明显你缺乏基本的 PHP 知识,所以我建议你先阅读一些 PHP 教程或观看一些 PHP 视频。

    现在回答你的问题

    echo '<table>';
    
    foreach($object->cdrs as $value) {
    echo '<tr>';
       echo '<td>' . $value->calldate . '</td>';
       echo '<td>' . $value->src . '</td>';
       echo '<td>' . $value->dst . '</td>';
       echo '<td>' . $value->channel . '</td>';
       //etc...
    echo '</tr>';
    }
    
    echo '</table>';
    

    希望这会有所帮助! :D

    【讨论】:

      猜你喜欢
      • 2021-04-06
      • 2019-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-16
      • 2022-01-24
      相关资源
      最近更新 更多