1

codeigniter で foreach ループを使用してクエリの結果を表示する際に問題が発生しています。ここに私のコントローラーがあります:

function viewall()
{
    $this->load->model('all');
    $data['query'] = $this->all->viewall();
    $this->load->view('all', $data);
}

モデル ファイル全体:

<?php
class All extends CI_Model
{

function insert_into_db()
{
    $data = array('Error' => $this->input->post('f1'),
                  'Solution' => $this->input->post('f2')
                 );
    $this->db->insert('Errors', $data);
}

function viewall()
{
    $query = $this->db->select("Error, Solution")->from("Errors")->get();
    return $query->result();
}

}

私の見解(どこに問題があると思うか)

<table class="table table-striped">
    <thead>
        <tr>
            <td><h3>Error</h3></td>
            <td><h3>Solution</h3></td>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($query->result_array() as $entry) ?>
        <tr>
            <td><?php echo $entry->Error; ?></td>
            <td><?php echo $entry->Solution;?></td>
        </tr>
        <?php endforeach ?>
    </tbody>
</table>
4

1 に答える 1

4

コントローラ:

function viewall()
{
    $this->load->model('all');
    $data['results'] = $this->all->viewall();
    $this->load->view('all', $data);
}

モデル:

function viewall()
{
    $query = $this->db->select("Error, Solution")->from("Errors")->get();
    return $query->result();
}

意見:

<table class="table table-striped">
    <thead>
        <tr>
            <td><h3>Error</h3></td>
            <td><h3>Solution</h3></td>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($results as $entry): ?>
        <tr>
            <td><?php echo $entry->Error; ?></td>
            <td><?php echo $entry->Solution;?></td>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>
于 2013-08-16T06:02:05.913 に答える