在查看传递数据我存储在一个$data
变量的SQL查询结果,并把它传递给一个search_view
像这样从我的模型:错误在笨
$this->db->like('LOWER(title)', strtolower($query));
$q = $this->db->get('questions');
$data = $q->row_array();
$this->load->view('search_view', array('data' => $data));
,我试图以显示所有结果在我看来,用以下结构:
<?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 } } ?>
其中$数据[“SEARCH_TYPE”]是我需要检查,看看执行的搜索类型,该位被测试,工作正常,没有必要担心它,但是,
我得到了一个非法的字符串偏移量错误,像我使用的用户名,标题和日期等所有变量。
eddit *例子转储:
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" }
由于某种原因,这是不返回不止一个问题,但应该有更多的用于执行搜索。
用'var_dump($ data);'来看你实际得到的东西。 – mario