Php Can';t循环Codeigniter HTML表中的数据
我想为我的数据库结果创建一个循环。但我无法使它在我的视图文件上工作 这是我的模型:Php Can';t循环Codeigniter HTML表中的数据,php,html,codeigniter,model-view-controller,Php,Html,Codeigniter,Model View Controller,我想为我的数据库结果创建一个循环。但我无法使它在我的视图文件上工作 这是我的模型: <?php class Dash_model extends CI_Model { public function __construct() { parent::__construct(); // Loading second db and running query. $CI =
<?php class Dash_model extends CI_Model {
public function __construct()
{
parent::__construct();
// Loading second db and running query.
$CI = &get_instance();
//setting the second parameter to TRUE (Boolean) the function will return the database object.
$this->db2 = $CI->load->database('db2', TRUE);
}
public function query0()
{
$query = $this->db2->query("SELECT name FROM table1 ORDER BY date");
return ($query->result());
}
public function query1()
{
$query = $this->db->query("MY QUERY HERE, RUNS OK");
$result = $query->result_array();
return $result;
}
public function query2()
{
$query = $this->db->query("MY QUERY HERE, RUNS OK");
$result = $query->result_array();
return $result;
}
public function query3()
{
$query = $this->db->query("MY QUERY HERE, RUNS OK");
$result = $query->result_array();
return $result;
}
public function query4()
{
$query = $this->db->query("MY QUERY HERE, RUNS OK");
$result = $query->result_array();
return $result;
}
}
以及:
我希望达到的结果应该是:
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Name</th>
<th>Transaction Success</th>
<th>Transaction Failure</th>
<th>Total Visit</th>
<th>Total Item</th>
</tr>
</thead>
<tbody>
<?php foreach (array_combine($result0, $result1, $result2, $result3, $result4) as $row)
{ ?>
<tr>
<td><?php echo $row->queryalias0; ?></td>
<td><?php echo $row->queryalias1; ?></td>
<td><?php echo $row->queryalias2; ?></td>
<td><?php echo $row->queryalias3; ?></td>
<td><?php echo $row->queryalias4; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
谢谢大家,谢谢你们的帮助…来自php.net
array_combine-使用一个数组作为键和
另一个原因是它的价值观
您使用了错误的方式array\u combine
函数。您可以改为尝试array\u merge
foreach (array_merge($result0, $result1, $result2, $result3, $result4) as $row)
来自php.net
array_combine-使用一个数组作为键和
另一个原因是它的价值观
您使用了错误的方式array\u combine
函数。您可以改为尝试array\u merge
foreach (array_merge($result0, $result1, $result2, $result3, $result4) as $row)
使用
array\u merge
代替…使用array\u merge
代替。。。
Message: Invalid argument supplied for foreach()
array array_combine ( array $keys , array $values )
foreach (array_merge($result0, $result1, $result2, $result3, $result4) as $row)