用户
 找回密码
 入住 CI 中国社区
搜索
查看: 5860|回复: 6
收起左侧

[已解决] 这个SQL语句怎么写

[复制链接]
发表于 2010-5-12 11:42:58 | 显示全部楼层 |阅读模式
select colum1 from table1,table2 where table1.colum1={$id} and table1.colum2=table2.colum1
这句用CI怎么做啊
  $this->db->select(colum1);
  $this->db->from(array('table1','table2'));
  $sql = "uid={$id} and  table1.colum2=table2.colum1
  $this->db->where($sql);
  $data['query'] = $this->db->get();
这样写不行吗
发表于 2010-5-12 12:10:25 | 显示全部楼层
干嘛非要写成那样的,你就直接用sql语句query就好啦
 楼主| 发表于 2010-5-12 12:23:27 | 显示全部楼层
回复 2# ywqbestever

恩,写不出来,最后还是直接SQL写的
发表于 2010-5-12 13:41:23 | 显示全部楼层
$this->db->select(colum1);
$this->db->from('table1');
$this->db->join('table2', 'table1.colum2=table2.colum1');
$this->db->where('uid', $id);

$data['query'] = $this->db->get();
发表于 2010-5-12 13:52:32 | 显示全部楼层
警告楼主一次,请不要重复发帖,我见到不是一次两次了。
发表于 2010-5-14 11:43:45 | 显示全部楼层
function get_goods_info($cid) {
        $this->db->select('colum1');
        $this->db->from('table1');
        $this->db->where('uid', $id);
        $this->db->join('table2', 'table1.colum2=table2.colum1', 'left');
        $query = $this->db->get();
        return $query->result();
    }
发表于 2010-5-14 21:31:35 | 显示全部楼层
ci的sql查询 ,老感觉很蹩脚.

本版积分规则