| 제목 | [초보]조인할 경우에 어케 하나요? | ||
|---|---|---|---|
| 글쓴이 | 헛발이 | 작성시각 | 2010/02/10 16:05:22 |
|
|
|||
|
이럴 경우에 처리 하는 방법이 있나요? test1테이블의 필드는 id, name test2테이블의 필드는 id, test1_id, name 이렇게 되어 있습니다. 그래서 모델에서...
$this->db->select('*');
$this->db->from('test1');
$this->db->join('test2', 'test1.id = test2.test1_id');
$query = $this->db->get();
이렇게 하였을 때요..test1의 name과 test2의 name과 필드명이 같잖아요... 그런데 뷰에선 그냥 $data['test1']['name'] 이렇게 할 방법은 없나요? |
|||
| 다음글 | 글 내용중 eval(), base64_encoding(... (5) | ||
| 이전글 | 위젯은... (1) | ||
|
변종원(웅파)
/
2010/02/10 20:57:16 /
추천
0
|
|
슈퍼개미
/
2010/02/23 20:51:08 /
추천
0
function using($table, $cond, $type = '')
{
if ($type != '')
{
$type = strtoupper(trim($type));
if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER')))
{
$type = '';
}
else
{
$type .= ' ';
}
}
// Extract any aliases that might exist. We use this information
// in the _protect_identifiers to know whether to add a table prefix
$this->_track_aliases($table);
$cond = $this->_protect_identifiers($cond);
// Assemble the JOIN statement
$join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' USING ('.$cond.')';
$this->ar_join[] = $join;
if ($this->ar_caching === TRUE)
{
$this->ar_cache_join[] = $join;
$this->ar_cache_exists[] = 'join';
}
return $this;
}
저는 join을 수정해서 추가사용했습니다. join할 이름이 같다면...
$this->db->using('테이블이름','동일필드이름','조인명');
$this->db->using('test1,'field','left');
|
일반 쿼리에서도 그렇게 쓸 방법이 없을겁니다.
$this->db->select('test1.name as name1, test2,name as name2');
이렇게 쓰시면 됩니다.