public function updateMemberdetail(Application_Model_Memberdetail $memberdetail)
{
$data = array(
'memberid' => $memberdetail->getMemberid(),
'membername' => $memberdetail->getMembername(),
'contact' => $memberdetail->getContact(),
'birthday' => $memberdetail->getBirthday(),
'email' => $memberdetail->getEmail(),
'address' => $memberdetail->getAddress(),
);
$auth= Zend_Auth::getInstance(); //declare zend_auth to get instance
$user= $auth->getIdentity(); //get identity of user
$userid = $user->userid; //get userid of user
$this->select() //select from usertable and memberdetail
->from(array('memberdetail', 'usertable')) //join memberdetail and usertable through memberid = username
->where('memberdetail.memberid = usertable.?', $userid);
$row = $this->fetchRow($select);
if ($row == true) //if row exist update row
{
$this->update($data, 'memberid = '. (int)($memberdetail->getMemberid()));
}
else
{
$this->insert($data); //if row doesnt exist, add it
}
}
您好,我在使用 if else 语句时遇到了一些问题。如果数据库中不存在,我想添加一行数据,但如果存在则更新它。但是,当我在数据库中没有该行时,它不会插入它。当我手动将一行插入数据库时,它会更新该行。