试图显示一个简单查询的结果。
[编辑]activitati.denumire
我认为我的查询有问题, and之间似乎存在冲突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
. 任何想法 ?