1
引用符と引用符の2つのテーブルと1つの共通フィールドQuoteNoがあります。 SNOは引用マスタの主キーです。私はsnoの最大を取得し、それを使用して私は2つの異なるテーブルに同じQuoteNoを挿入したい。 Heres my code。最後に挿入されたIDを取得したい
$response = '';
$customer=TableRegistry::get('quotationmaster');
$query=$customer->query();
$this->set(array('data'=>$query));
$response = $customer->find();
foreach($response as $row)
{
//echo $row['QuoteNo'];
$x++;
}
$qno = $x + 1;
$nqno = 'Q1-'.$qno;
$query->insert(['QuoteNo'])->
values(['QuoteNo'=>$nqno])->execute();
if($query)
{
$this->Flash->success('Saved');
$this->redirect(['controller'=>'Stockcheck','action'=>'index']);
}
$quotedetails=TableRegistry::get('quotationmaster');
$detquery=$quotedetails->query();
$options = $detquery->select(['QuoteNo'],['SerialNO' => $query->func()->MAX('SNO')]);
$qresponse = $quotedetails->find('all', $options);
Any helps are appreciable...
違反はありませんが、それは本当に奇妙に見えます。 '$ query'のテストは常に真実で、' Query :: select() 'の2番目の引数は配列ではなくブール値をとり、' Table :: find() 'の2番目の引数は配列を必要とします。クエリオブジェクト。あなたは、そのコードを実行するときにエラーの束を参照する必要があります。あなたはあなたがそこで何をしているかを知っていますか?どのように動作するかをよりよく理解し、手動でレコードを挿入するのではなく 'Table :: save()'を使用するように、ドキュメントを少しずつ調べることをお勧めします。 – ndm