English 中文(简体)
简单的密码查询+显示
原标题:simple codeigniter query + results display won t display

我试图从我的数据库中显示数据,从密码的角度。 种子应该简单,但只是不奏效。

I m 留下2个错误:也认为,没有界定的可变性(驱逐者,认为)和无效理由为php foreach。

我如何能够做到这一点? 下面的法典。

<><><><><>><>>>><>>>>>>

function displayMovies() {

$this->load->model( movie_list_model );

$data[ movielist ] = $this->movie_list_model->getList();

$this->load->view( movielist_view , $data);
}

<><><>>>>

function getList() {

        $query = $this->db->query( SELECT firstname, lastname, favorite_movie FROM movies );
        return $query->result();


        if ($query->num_rows() > 0) {

        foreach ($query->result_array() as $row)
        {
             echo $row[ firstname ];
             echo $row[ lastname ];
             echo $row[ favorite_movie ];
        }   
    }

      <?php foreach($movielist as $mlist)
        {
            echo  $mlist->firstname .  <br /> ; 
            echo  $mlist->lastname .  <br /> ; 
            echo  $mlist->favorite_movie; 
        }
      ?>
最佳回答

如果问询没有发现任何行文,就会退回<代码>null,从而在你看来造成<代码>未界定<>代码/代码”错误。 无效的论点是错误的,因为你可以通过<代码>null<>/code> t。

在你看来,安全将包含这样的内容:

if($movielist)
{
    /* foreach() {} */
}

此外,你的模型只能是数据回馈(而不是重复数据)。

function getList() {
    $query = $this->db->query( SELECT firstname, lastname, favorite_movie FROM movies );
    return $query->result(); /* returns an object */
    // Alternatively:
    // return $query->result_array(); /* returns an array */
}

我也建议使用。 积极纪录:

function getList() {
    $this->db->select( firstname );
    $this->db->select( lastname );
    $this->db->select( favorite_movie );

    $query = $this->get( movies );
    return $query->result();
}

Good luck!

问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签