Reputation: 2881
Trying to display results of a simple query.
[EDIT] I think my query is problematic, there seems to be a conflict between activitati.denumire
and proiecte.denumire
, but I don't know how to work around that.
Model:
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;
}
Controller:
<?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);
}
}
?>
View:
<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>
Strange part is: idA
and tascuri
work just fine, the rest don't.
I also did a var_dump($query)
and i got a two dimensional array:
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" }
}
Yet idA
and tascuri
worked even when I had a single foreach
. Any idea ?
Upvotes: 0
Views: 6068
Reputation: 6896
Nothing you are looking for matches an index in the $row
array other than idA
and tascuri
. You have it here pretty clearly - each row has elements at idA
, denumire
, tascuri
, bugetFolosit
, and bugetAlocat
but you're looking for activitati.denumire
, etc, which aren't indeces in the $row
array, hence the error.
You should be doing echo $row['denumire'];
. Why are you trying to access $row['activitati.denumire']
??
Upvotes: 0