如何在数据库中设置数组? (笨)

时间:2018-01-02 05:24:15

标签: php codeigniter

我想将数据库中的字符串传递给我的视图。在我的模型中,我提出了这个:

public function getSeries($limit = 10, $order = 'id_s', $das = 'desc')
    {
        $this->db->select('*')
                 ->from('s_series')
                 ->where(array('nom_s' => $nom_s))
                 ->order_by($order, $das)
                 ->limit($limit);
        $query = $this->db->get();

        return $query->row_array();
    }

在我的控制器中

$data['lastSeries'] = $this->series->getSeries();

在我看来

<? foreach($lastSeries as $lserie): ?>
                            <li>
                            <article class="pli-lg">
    <header>
        <figure><a href="http://todoanimes.com/pelicula/hakuouki-movie-2-shikon-soukyuu.html">
        <img src="https://todoanimes.com/img/animes/portadas_260x310/hakuouki-movie-2-shikon-soukyuu.jpg" alt="Hakuouki Movie 2: Shikon Soukyuu"><span class="iconb-ver"></span></a></figure>
    </header>
    <section>
        <h2><a href="http://todoanimes.com/pelicula/hakuouki-movie-2-shikon-soukyuu.html"><? echo $lserie['nom_s']; ?></a></h2>
        <a class="botn-smll" href="http://todoanimes.com/pelicula/hakuouki-movie-2-shikon-soukyuu.html">PELICULA</a>
    </section>
</article>  

<article class="pli-sm">
    <header>
        <figure><a href="http://todoanimes.com/pelicula/taifuu-no-noruda.html">
        <img src="https://todoanimes.com/img/animes/portadas_50x70/taifuu-no-noruda.jpg" alt="Taifuu no Noruda"><span class="iconb-ver"></span></a></figure>
    </header>
    <section>
        <h2><a href="http://todoanimes.com/pelicula/taifuu-no-noruda.html">Taifuu no Noruda</a></h2>
        <a class="botn-smll" href="http://todoanimes.com/pelicula/taifuu-no-noruda.html">PELICULA</a>
    </section>  
</article>

                </li>
            <?php endforeach; ?>

但是当我想在我的视图中查看它时会显示以下信息:

enter image description here

有人知道,问题是什么?

我已从我的代码中删除了这一行:

->where(array('nom_s' => $nom_s))

但现在在我的源代码中显示:

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Illegal string offset 'nom_s'</p>
<p>Filename: pages/home.php</p>
<p>Line Number: 41</p>
    <p>Backtrace:</p>
            <p style="margin-left:10px">
            File: C:\xampp\htdocs\application\views\pages\home.php<br />
            Line: 41<br />
            Function: _error_handler            </p>

            <p style="margin-left:10px">
            File: C:\xampp\htdocs\application\controllers\Pages.php<br />
            Line: 25<br />
            Function: view          </p>

            <p style="margin-left:10px">
            File: C:\xampp\htdocs\index.php<br />
            Line: 315<br />
            Function: require_once          </p>

字符串nom_s是我的表s_series

的字段

2 个答案:

答案 0 :(得分:1)

更改你的最后一行

返回$ query-&gt; result_array();

答案 1 :(得分:0)

请先检查您的查询,您的查询是对还是错。

试试这个:

$data['lastSeries'] = $this->series->getSeries();

echo $this->db->last_query();