2

I would like to pass a string from my database to my view. In my model I've put this:

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();
    }

In my controller

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

In my view

<? 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; ?>

But when I want to view in my view it show this message:

enter image description here

Somebody know, what is the problem?

I've deleted this line from my code:

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

but now in my source code show this:

<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>

the string nom_s is a field of my table s_series

3
  • show your entire controller method Commented Jan 2, 2018 at 5:32
  • How you getting $nom_s in your model? Commented Jan 2, 2018 at 5:45
  • when I call my table from my db $this->db->select('*') ->from('s_series') ->where(array('nom_s' => $nom_s)) ->order_by($order, $das) ->limit($limit); $query = $this->db->get(); Commented Jan 2, 2018 at 5:49

2 Answers 2

1

Change Your Last Line

return $query->result_array();

Sign up to request clarification or add additional context in comments.

1 Comment

perfect, thanks a lot. I've solved my problem with your help
0

Please check your query first, is your query right or wrong.

Try this:

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.