簡體   English   中英

PHP從兩個表中獲取數據

[英]Php fetch data from two tables

我必須編輯一個表單,其中包含兩個表的數據。 一個是主人,另一個是用戶。 首先將數據保存在用戶表中,使用該ID將其余數據保存在主表中。 下面是我的編輯代碼,我應該怎么做才能獲取數據並進行編輯。

     public function edit() {
    $id = $this->request->params['pass'][0];
    $this->Master->id = $id;
    if( $this->Master->exists()){
        if( $this->request->is( 'post' ) || $this->request->is( 'put' ) ){
            if( $this->Master->save( $this->request->data ) ){
                $this->redirect(array('action' => 'index'));
            }
            else { 
                $this->Session->setFlash('Unable to edit row. Please, try again');
            } 
        }
        else { 
          $this->request->data = $this->Master->read();
        }
    } 
}

有人可以幫忙嗎..

通過以下方式更新代碼:

$this->request->data = $this->Master->read(null, $id);

$this->set('masterArr',$this->Master->find('all',array('conditions' =>
array('Master.id ' => $id))));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM