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


Right way to fetch and display massive php variables via html

当我们应该使用 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);

您可以获取所有变量并将其存储在array中。有关如何在数组中存储 MySQL 值,请参阅此问题,如何在数组中存储 mysql 数据的行/列。

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

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

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