尝试显示简单查询的结果。
[编辑] 我认为我的查询存在问题,activitati.denumire
和proiecte.denumire
之间似乎存在冲突,但我不知道如何解决这个问题
型号:
public function getActivities() {
$this->db->select('idA');
$this->db->select('activitati.denumire');
$this->db->select('tascuri');
$this->db->select('activitati.bugetFolosit');
$this->db->select('proiecte.denumire');
$this->db->select('proiecte.bugetAlocat');
$this->db->from('activitati');
$this->db->from('proiecte');
$this->db->where('activitati.aprobat = 0');
$this->db->where('activitati.idProiect = proiecte.idProiect ');
$result = $this->db->get();
$data = $result->result_array();
return $data;
}
控制器:
<?php
class ApproveActivity extends CI_Controller{
function __construct() {
parent::__construct();
}
public function index () {
$this->getData();
}
public function getData () {
$this->load->model("db_Activities");
$data['query'] = $this->db_Activities->getActivities();
$this->loadView($data);
}
public function approve () {
}
public function loadView ($data) {
$this->load->view("ViewActivityApproval",$data);
}
}
?>
查看:
<table border="1">
<tr>
<th>ID</th>
<th>Denumire</th>
<th>Tascuri</th>
<th>Buget Folosit</th>
<th>Proiect: Denumire</th>
<th>Proiect: Buget Alocat</th>
</tr>
<?php
var_dump($query);
foreach ($query as $row): ?>
<tr>
<td><?php echo $row['idA'];?></td>
<td><?php echo $row['activitati.denumire'];?></td>
<td><?php echo $row['tascuri'];?></td>
<td><?php echo $row['activitati.bugetFolosit'];?></td>
<td><?php echo $row['proiecte.denumire'];?></td>
<td><?php echo $row['proiecte.bugetAlocat'];?></td>
</tr>
<?php endforeach; ?>
</table>
奇怪的部分是:idA
和tascuri
工作正常,其余部分没有。
我也做了一个var_dump($query)
,我得到了一个二维数组:
array(2) {
[0]=> array(5) {
["idA"]=> string(2) "12"
["denumire"]=> string(6) "Test 1"
["tascuri"]=> string(11) "bla bla bla"
["bugetFolosit"]=> string(3) "200"
["bugetAlocat"]=> string(4) "2500" }
[1]=> array(5) {
["idA"]=> string(2) "13"
["denumire"]=> string(6) "Test 2"
["tascuri"]=> string(11) "CursStiinta"
["bugetFolosit"]=> string(3) "200"
["bugetAlocat"]=> string(3) "100" }
}
即使我有一个idA
,tascuri
和foreach
仍有效。有什么想法吗?
答案 0 :(得分:0)
除了$row
和idA
之外,您所寻找的任何内容都与tascuri
数组中的索引相匹配。你在这里很清楚 - 每一行都有idA
,denumire
,tascuri
,bugetFolosit
和bugetAlocat
的元素,但你正在寻找{{ 1}}等,它们不是activitati.denumire
数组中的indeces,因此是错误。
你应该做$row
。你为什么试图访问echo $row['denumire'];
??