0

试图显示一个简单查询的结果。

[编辑]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" } 
}

然而idAtascuri即使我有一个foreach. 任何想法 ?

4

1 回答 1

0

除了和 之外,您要查找的任何内容都与$row数组中的索引不匹配。你在这里很清楚 - 每行都有元素, , , , 并且你正在寻找, 等等,它们不是数组中的 indeces,因此是错误的。idAtascuriidAdenumiretascuribugetFolositbugetAlocatactivitati.denumire$row

你应该这样做echo $row['denumire'];。你为什么要访问$row['activitati.denumire']??

于 2013-04-25T04:51:32.257 回答