通过html获取和显示大量php变量的正确方法

时间:2016-02-24 12:58:32

标签: php html codeigniter

当我们应该使用php获取大约200个数据库条目并使用html在页面中显示它们时,最好的方法是什么。现在我正在这样做<?php echo $variable1?;>,,,,<?php echo $variable200;?>,感觉加载有点慢。还有其他选择吗?

模型:

$query_str = "select *from table where sl_no='$report_id' and code='$code'";
$row=$query->row_array();
    return $row;

控制器:

$reports=$this->patient_model->fetch_previous_reports($pat_lab_id);
    echo json_encode($reports);

1 个答案:

答案 0 :(得分:0)

您可以获取所有变量并将其存储在array中。请参阅此问题How to store row/column of mysql data in array,了解如何在数组中存储MySQL值。

有关array的更多信息:http://www.w3schools.com/php/php_arrays.asp

然后,回显存储在数组中的所有值:

foreach ($array as $item) {
    echo $item . '<br/>';
}