【问题标题】:Php fetch data from two tablesphp从两个表中获取数据
【发布时间】:2016-01-12 05:30:32
【问题描述】:

我必须编辑一个包含两个表格数据的表格。 一个是主人,另一个是用户。首先将数据保存在用户表中 并使用该 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();
        }
    } 
}

有人可以帮忙吗..

【问题讨论】:

  • 为什么要获取数据。使用用户表 ID,您可以编辑用户字段。匹配主表中的用户 id 和 user_id。如果相同,则获取主表 ID 并编辑主字段。这是我的理解。如果我错了,请解释更多你的问题。
  • 如果您得到了您需要的答案,那么我将在答案中发布我的命令。请确认我
  • 请解释更多并告诉我你想要什么输出

标签: php cakephp


【解决方案1】:

通过以下方式更新您的代码:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多