2011-12-07 5 views
2

하나의 쿼리로 여러 행을 선택할 수 있기를 원합니다. 이런 식으로 할 수 있을지 궁금 해서요? 정의에활성 레코드 : db 개체 작업

$teamsQuery = $this->db; 

foreach($teamids as $teamid) 
$teamsQuery->where('teamid', $teamid); 

$teamsQuery->get('team'); 

$teams = $teamsQuery->result(); 

print_r($teams); 

답변

1

ActiveRecord는 객체에 데이터베이스에 단일 행을 래핑하고 여기에 비즈니스와 지속성 로직을 첨부합니다. 하나의 쿼리로 여러 행을 가져 오려면 TableDataGateway을보십시오.

TableDateGateway에서 findTeamsByIds 메서드를 사용하면 전체 ID 배열을 전달한 다음 SELECT … WHERE … IN 쿼리에서 해당 ID를 가져올 수 있습니다.

0

당신은

/** 
* get all data from the table 
* 
* @param string $sql - mySQL query string 
* 
* @return data as associative array 
* */ 
function getAll($sql) { 
    $res = mysql_query($sql); 

    if (!$res) { 
     die(mysql_error()); 
    } 

    // Convert to array 
    $ret = array(); 
    while ($row = mysql_fetch_assoc($res)) { 
     // Add to array 
     $index = count($ret); 
     $ret[$index] = $row; 
    } 

    return $ret; 
} 
+0

루프 동안 것이 무엇 기능의 유형을 시도 할 수 있습니다? 이 함수는 연관 배열로 행을 가져온 다음 $ ret [$ index]에 행을 할당하지만 $ index는 항상 $ ret와 같은 번호이므로 마지막으로 반환 된 행만 포함합니다. – Gordon