I'm storing an SQL query result in a $data variable and passing it to a search_view like this from my model:
$this->db->like('LOWER(title)', strtolower($query));
$q = $this->db->get('questions');
$data = $q->row_array();
$this->load->view('search_view', array('data' => $data));
And I am trying to display all results in my view using following structure:
<?php if ($data['search_type'] == 'question') {
foreach ($data as $question) {
?>
<div class="question-result">
<h2><?php echo $question['title']; ?></h2>
<p>Posted by: <a href="#"><?php echo $question['username']; ?>username</a></p>
<p>Date Posted: <?php echo $question['date']; ?></p>
</div>
<?php } } ?>
Where $data['search_type'] is something I need to check to see what type of search was performed, this bit is tested and works fine, no need to worry about it, however
I get an illegal string offset error for all variables like username, title and date that I use.
eddit* example dump:
array(7) { ["question_id"]=> string(1) "3" ["title"]=> string(19) "First Question Ever" ["content"]=> string(13) "Hello Content" ["date"]=> string(19) "2015-01-03 15:08:30" ["user_id"]=> string(2) "14" ["username"]=> string(4) "Ilya" ["search_type"]=> string(8) "question" }
for some reason this is not returning more than one question, although there should be more for a search performed.
var_dump($data);to see what you actually got.