简体   繁体   English

回显输出SQL JOIN?

[英]Echo output sql JOIN?

How should echo output following query? 查询后应如何echo输出?

My tables in MySQL database: 我在MySQL数据库中的表:

在此处输入图片说明

$query = $this->db->query('SELECT geo.order FROM Store_Information si JOIN Geography AS geo ON geo.id = si.id WHERE si.name LIKE "%' . $find1 . '%"');

My try not work: 我的尝试不起作用:

if ($query->num_rows() > 0){
   foreach($query as $val) {
      $query_out = $query->row();
      echo $query_out->order . '<br>';
   }
}
else {
    echo '0';
}

What do I do? 我该怎么办?

You need to add ->result() in your foreach loop: 您需要在foreach循环中添加->result()

// from the docs
$query = $this->db->query("YOUR QUERY");

foreach ($query->result() as $row)
{
    echo $row->title;
    echo $row->name;
    echo $row->body;
}

http://codeigniter.com/user_guide/database/results.html http://codeigniter.com/user_guide/database/results.html

You should read this guide to better understand how to use codeigniter query results. 您应该阅读指南,以更好地了解如何使用codeigniter查询结果。

basically this code can help: 基本上,这段代码可以帮助:

if($query->num_rows() > 0){
    foreach($query->result_array() as $row) {
        var_dump($row);
    }
}

and don't forget to $query->free(); 并且不要忘记$query->free(); your result 你的结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM