2012-07-11 2 views
1

xml 피드를 가져 오는 파일에서 매 5 분마다 cronjob을 실행하고 있습니다. 데이터베이스에 피드를 추가하는 순간에 아래에 표시 될 수 있습니다.codeignitor 활성 레코드가있는 데이터베이스에 중복 값을 삽입하지 마십시오

title, this is a new title 
title, this is another title 

하지만 크론가 실행될 때 내가 가지고 문제가 다시 나는 아래

title, this is a new title 
title, this is another title 
title, this is a new title 
title, this is another title 

을 얻고 그것을 다시 등

title, this is a new title 
title, this is another title 
title, this is a new title 
title, this is another title 
title, this is a new title 
title, this is another title 

그리고 .....

을 실행할 때

내 cron 작업이 계속 실행될 수 있도록 동일한 제목의 데이터베이스에 레코드가없는 경우에만 레코드를 삽입하고 싶습니다. ning 그리고 다른 제목을 알아 차릴 때 그것은 db에 그것을 삽입합니다.

나는 별도의 옵션을 많이 시도 같은 not_like 등

누군가가 나에게 이렇게하는 가장 좋은 방법을 말할 수 ???

감사합니다는,

) 나는 그것이 내가 여기에 파티에 조금 늦게 해요 알고 있지만

function addResults($data){ 

    $this->db->select('title'); 
     $this->db->from('articles'); 
     $this->db->where('title = ' . "'" . $data['title'] . "'"); 
     //$this->db->limit(1); 
     $query=$this->db->get(); 
     echo $query->num_rows(); 
     if($query->num_rows()){ 

    }else{ 
     echo 'New Record ' . $data['title']; 
     $this->db->set('date', 'NOW()', FALSE); 
      $this->db->insert('articles', $data); 
     } 

    } 

답변

2

가 약간있는 다음하지만 확실히 가장 좋은 방법의 잭 함께 할 관리 더 나은 방법 :

function addResults($data) 
{ 
    $result = $this->db->get_where('articles', array('title ' => $data['title'])); 
    $inDatabase = (bool)$result->num_rows(); 

    if (!$inDatabase) 
    { 
     echo 'New Record ' . $data['title']; 
     $this->db->set('date', 'NOW()', FALSE); 
     $this->db->insert('articles', $data); 
    } 
} 
+0

+1. 시도하고 내 코드에서 일했다. tnx – jned29