【问题标题】:Nothing happened when I tried to echo data from join table in CodeIgniter当我尝试从 CodeIgniter 的连接表中回显数据时,什么也没发生
【发布时间】:2014-08-30 11:00:21
【问题描述】:

我的模特:

public function category($cat)
{
    $this->db->select('c.id, c.cat2, c.category, m.id, m.date, m.when_date, m.when_time, m.where_m');
    $this->db->from('category c');
    $this->db->where('c.category', '$cat');
    $this->db->join('meeting m', 'm.id_cat = c.id');
    $result = $this->db->get();
    return $result->result();
}

我的控制器:

    $data['meeting'] = $this->users_m->category($cat);
    $this->load->view('category', $data);

我的看法:

<table> 
<?php foreach($meeting as $row): ?>
    <tr>
        <td><?php echo ($row->id); ?> </td>
        <td><?php echo ($row->id_cat); ?> </td>
        <td><?php echo ($row->date); ?> </td>
        <td><?php echo ($row->when_date); ?> </td>
        <td><?php echo ($row->where_m); ?></td>
    </tr> 
<?php endforeach; ?>
</table>

当我尝试回显这些数据时,什么也没发生;没有错误信息。任何想法?我是新手。

【问题讨论】:

  • 使用$this-&gt;db-&gt;last_query() 查找正在执行的sql查询...
  • 解析错误:语法错误,第 23 行 C:\xampp\htdocs\ci\application\models\users_m.php 中的意外“返回”(T_RETURN)
  • 哪一行不是23?

标签: php mysql codeigniter join html-table


【解决方案1】:

where 子句可能是问题所在。你写道:`

$this->db->where('c.category', '$cat');

我认为它应该看起来像:

$this->db->where('c.category', $cat);

(不带单引号)

所以查询是将类别与字符串 $cat 进行比较。我想这不会在您的数据库中。所以结果会是空的。

【讨论】:

  • 他在评论中发布了错误消息..请检查。
  • 非常感谢,这有帮助:)
  • 我检查了评论,我知道这可能会导致问题 ;),没问题 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-29
  • 1970-01-01
  • 2017-06-10
  • 2019-07-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多