【问题标题】:How to display the results in table,based on array如何在表格中显示结果,基于数组
【发布时间】:2017-07-21 07:03:09
【问题描述】:

这里我有一个数组,我想以表格格式显示数组值,我是 PHP 7.1 的新手,如果有人知道意味着 - 更新我的答案,我试过但我无法得到答案

print_r($companyResponse);

Array
(
    [status] => success
    [message] => Total 3 record(s) found.
    [total_record] => 3
    [data] => Array
    (
        [0] => Array
            (
                [companyId] => 3
                [companyName] => TCS
                [noOfDivision] => 7
                [companyAddress] => JP nagar
                [companyStatus] => 0
            )

        [1] => Array
            (
                [companyId] => 2
                [companyName] => IBM
                [noOfDivision] => 5
                [companyAddress] => Domlur
                [companyStatus] => 0
            )

        [2] => Array
            (
                [companyId] => 1
                [companyName] => Quikr
                [noOfDivision] => 10
                [companyAddress] => Manyatha Tech Park,Bangalore
                [companyStatus] => 0
            )
    )
)

表格

<table id="demo-dt-basic" class="table table-striped table-bordered" cellspacing="0" width="100%" style="">
    <thead>
        <tr>
            <th>Company</th>
            <th>No of Division</th>
            <th >Company Address</th>
            <th>Action</th>
        </tr>
    </thead>
<tbody>
    <tr>
        <?php
            $companyResponse = GetResponse(API_URL.'getCompanies');
        ?>
        <td>1</td>
        <td>5</td>
        <td>TCS</td>
      <td>
         <button class="btn btn-success actionbtn"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Edit</button>
         <button class="btn btn-danger actionbtn" data-toggle="modal" data-target="#DeleteModal"><i class="fa fa-trash-o" aria-hidden="true"></i> Delete</button>
      </td>
   </tr>
</tbody>
</table>

【问题讨论】:

    标签: php php-7.1


    【解决方案1】:

    试试这个

    <table>
    <thead>
    <tr>
        <td>Company Id</td>
        <td>Company Name</td>
        <td>no Of Division</td>
        <td>Company Address</td>
        <td>Company Status</td>
    </tr>
    </thead>
    <tbody>
    <?php
    foreach ($companyResponse['data'] as $result) { ?>
        <tr>
            <td><?php echo $result['companyId']; ?></td>
            <td><?php echo $result['companyName']; ?></td>
            <td><?php echo $result['noOfDivision']; ?></td>
            <td><?php echo $result['companyAddress']; ?></td>
            <td><?php echo $result['companyStatus']; ?></td>
        </tr>
    
        <?php
    }
    ?>
    </tbody>
    

    【讨论】:

      猜你喜欢
      • 2020-01-14
      • 2021-04-26
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      • 2012-12-07
      • 2019-07-19
      • 2015-02-16
      • 1970-01-01
      相关资源
      最近更新 更多