2017-06-29 2 views
0

私はさまざまな可能性を試しましたが、何もうまくいかず、チュートリアルでも例が見つかりませんでした。私は与えられたファイル名の最後のインポートを取得したいので、ISTは、SQLのようでなければなりません私のモデルの最後のレコードセットを選択するための構文

public function getlastImport($filename) 
{ 
    //$id = (int) $id; 
    $rowset = $this->tableGateway->select(['Path' => $filename]); 
    $row = $rowset->current(); 
    if (! $row) { 
     throw new RuntimeException(sprintf(
       'Could not find row with identifier %d', 
       $id 
       )); 
    } 

    return $row; 
} 

select max(ID) from table where filename = $filename; 

しかし、どのようになります

私は私のmodelclassのメソッドを持っていますこの場合の正しい構文ですか?これはあなたを助けるでしょう

public function getlastImport($filename) 
{ 

    $select = $this->tableGateway->getSql()->select(); 
    $select->columns(array('id', 'filename', 'label')); 
    $select->where(array('filename' => $filename)); 
    $select->order("id DESC"); 
    $select->limit(1); 

    $result = $this->tableGateway->selectWith($select); 
    $row = $result->current(); 

    if (! $row) { 
     throw new RuntimeException(sprintf(
      'Could not find row with identifier %d', 
      $id 
     )); 
    } 

    return $row; 
} 

希望は、あなたのモデルで、次のよう

答えて

1

SQLクエリは

"SELECT * FROM table_name WHERE filename={$filename} ORDER BY id DESC LIMIT 1" 

使用する必要があります!

+0

質問は、私のモデルに書き込む方法でした。 –

+0

ちょうど編集されたコード!それがあなたのために働くかどうか私達にお知らせください! – unclexo

+0

それは働いて、構文fprのおかげで、私はrowfunction maxを実装するために探していた、このistかなりeasiert –

関連する問題