-1

我有下面的功能,告诉数据库天气更新或插入取决于是否找到电子邮件地址这工作正常但是我仍然有一些$POST信息需要进入另一个表,具体取决于id

我已经解决了,对于该if($emailCheck != FALSE)语句,我可以运行另一个insert语句并id在其中设置

我的问题是我如何才能为声明insert中的新信息实现这一目标else

插入功能:

function Insert()
{
  $emailCheck = $this->checkEmail($email);

  if($emailCheck != FALSE)
  {
    updateQuery by $emailCheck['id'])); // The email address is found so we update the data

  }else{

    Jojo::insertQuery; // The email address is not found so we insert the new row
  }
}

检查功能:

function checkEmail($email)
{
     $email = $POST['Email'];

    if($email)
    {
        $candemail = selectRow("SELECT * FROM {table} WHERE email=?",$email);

        if(isset($candemail['email']))
        {
            return $candemail;
        } else {
            return FALSE;
        }
    }
}

全功能:

  function candidateInsert($fields, $candiatefilename,$jobid)
    {
      $emailCheck = Jojo_Plugin_name_jobs_apply::checkCandidateEmail($email);

      if($emailCheck != FALSE)
      {
        //Jojo::updateQuery("UPDATE {db} SET first_name=?,last_name=?,home_phone=?,work_phone=?,mobile_phone=?,email=?,skype=?,contact_method=?,location=?,location_other=?,cv_path=? WHERE id=?", array($fields['FirstName'],$fields['LastName'],$fields['HomePhone'],$fields['WorkPhone'],$fields['MobilePhone'],$fields['Email'],$fields['Skype'],$fields['ContactMethod'],$fields['Location'],$fields['LocationOther'],$candiatefilename, $emailCheck['id']));
        //Jojo::insertQuery("INSERT INTO {refocus_candidate_job} SET candidateID=?,jobID=?,appliedDate=?", array($emailCheck['id'],$jobid,date("d/m/y")));
    }else{
        Jojo::insertQuery("INSERT INTO {db} SET first_name=?,last_name=?,home_phone=?,work_phone=?,mobile_phone=?,email=?,skype=?,contact_method=?,location=?,location_other=?,cv_path=?", array($fields['FirstName'],$fields['LastName'],$fields['HomePhone'],$fields['WorkPhone'],$fields['MobilePhone'],$fields['Email'],$fields['Skype'],$fields['ContactMethod'],$fields['Location'],$fields['LocationOther'],$candiatefilename));

        $id = Jojo::insertQuery;

        //Jojo::insertQuery("INSERT INTO {db_candidate_job} SET candidateID=?,jobID=?,appliedDate=?", array($id,$jobid,date("d/m/y")));

        }
    }
4

2 回答 2

1

它在 Jojo 文档中说。如果要获取新插入行的 id,只需使用

function Insert()
{
  $emailCheck = $this->checkEmail($email);

  if($emailCheck != FALSE)
  {
    updateQuery by $emailCheck['id'])); // The email address is found so we update the data
    $id = $emailCheck['id'];
  }else{

    $id = Jojo::insertQuery; // The email address is not found so we insert the new row
  }
  //at this point $id holds the id of the row.
}

然后,在 if/else 语句之后,您可以在第二个表上运行代码,知道您拥有行的 ID,无论哪种情况(INSERT/UPDATE)。

于 2012-09-20T05:28:39.470 回答
1

尝试在 else 语句中按以下顺序执行您的代码。

第一的

$id = Jojo::insertQuery("INSERT INTO {db} SET first_name=?,last_name=?,home_phone=?,work_phone=?,mobile_phone=?,email=?,skype=?,contact_method=?,location=?,location_other=?,cv_path=?", array($fields['FirstName'],$fields['LastName'],$fields['HomePhone'],$fields['WorkPhone'],$fields['MobilePhone'],$fields['Email'],$fields['Skype'],$fields['ContactMethod'],$fields['Location'],$fields['LocationOther'],$candiatefilename));

第二

Jojo::insertQuery("INSERT INTO {db_candidate_job} SET candidateID=?,jobID=?,appliedDate=?", array($id,$jobid,date("d/m/y")));
于 2012-09-20T07:36:54.190 回答