如何在控制器的代码点火器表中显示值?

时间:2016-12-29 08:28:14

标签: php arrays codeigniter

我在代码点火器控制器中有一个数组

foreach($array as $row) {
    echo $row['_source']['shape'];
    echo "<br>";
    echo $row['_source']['cut'];
    echo "<br>";
    echo $row['_source']['color'];
    echo "<br>";
    echo $row['_source']['clarity'];
    echo "<br>";
    echo $row['_source']['lab'];
    echo "<br>";
    echo $row['_source']['polish'];
    echo "<br>";
    echo $row['_source']['symmetry'];
    echo "<br>";
    echo $row['_source']['stone_id'];
    echo "<br>";
    echo $row['_source']['fluorescence'];
    echo "<br>";
    echo $row['_source']['cert_no'];
    echo "<br>";
    echo $row['_source']['location'];
    echo "<br>";
}

给了我两组不同的值

我得到的第一批价值

围绕3X D如果GIA VG G id01 FNT xy01 india

我得到的第二组价值

heart 2X f IF IGI VG G id01 FNT xy01 china

现在我想在视图部分的表格中显示所有值。

2 个答案:

答案 0 :(得分:1)

首先将您的数据发送到以下视图:

//Retrive your data here and put in  $result
$data['res']=$result;
$this->load->view('view_page', $data);

然后在您的视图页面

<table>
<?php 
foreach($res as $row) {
    echo "<tr>";
    echo "<td>".$row['_source']['shape']."</td>";
    echo "<td>".$row['_source']['cut']."</td>";
    echo "<td>".$row['_source']['color']."<td>";
    echo "<td>".$row['_source']['clarity']."</td>";
    echo "<td>".$row['_source']['lab']."</td>";
    echo "<td>".$row['_source']['polish']."</td>";
    echo "<td>".$row['_source']['symmetry']."</td>";
    echo "<td>".$row['_source']['stone_id']."</td>";
    echo "<td>".$row['_source']['fluorescence']."</td>";
    echo "<td>".$row['_source']['cert_no']."</td>";
    echo "<td>".$row['_source']['location']."</td>";
    echo "</tr>";           
     }
?>
</table>

答案 1 :(得分:0)

在控制器中:

$data['your_array'] = $array;
$this->load->view('view_page', $data);

查看页面:

<table>
<?php 
if(is_array($values) && count($your_array) > 0) {
    foreach($your_array as $row) {
        ?>
        <tr>
            <td><?php echo $row['_source']['shape']; ?></td>
            <td><?php echo $row['_source']['cut']; ?></td>
            <td><?php echo $row['_source']['color']; ?><td>
            <td><?php echo $row['_source']['clarity']; ?></td>
            <td><?php echo $row['_source']['lab']; ?></td>
            <td><?php echo $row['_source']['polish']; ?></td>
            <td><?php echo $row['_source']['symmetry']; ?></td>
            <td><?php echo $row['_source']['stone_id']; ?></td>
            <td><?php echo $row['_source']['fluorescence']; ?></td>
            <td><?php echo $row['_source']['cert_no']; ?></td>
            <td><?php echo $row['_source']['location']; ?></td>
        </tr> 
        <?php   
    }
}
?>
</table>