Reputation: 95
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:
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
Upvotes: 2
Views: 112
Reputation: 58
Change Your Last Line
return $query->result_array();
Upvotes: 1
Reputation: 336
Please check your query first, is your query right or wrong.
Try this:
$data['lastSeries'] = $this->series->getSeries();
echo $this->db->last_query();
Upvotes: 0