简体   繁体   English

PHP从两个表中获取数据

[英]Php fetch data from two tables

I have to edit a form where it contains datas form two tables. 我必须编辑一个表单,其中包含两个表的数据。 one is master and another user. 一个是主人,另一个是用户。 first the data is saved in user table and with that id the remaining datas get saved in master table. 首先将数据保存在用户表中,使用该ID将其余数据保存在主表中。 Below is my edit code.What should i do to fetch the data and edit it. 下面是我的编辑代码,我应该怎么做才能获取数据并进行编辑。

     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();
        }
    } 
}

Could somebody help pls.. 有人可以帮忙吗..

Update your code by : 通过以下方式更新代码:

$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