0

class Application_Model_DbTable_Email extends Zend_Db_Table_Abstract
{

protected $_name = 'memberdetail';  

public function sendEmail($email)
{

    $email = $_POST['email'];
    $userid = ($this->select('userid')
            ->from('usertable', 'memberdetail')
            ->where('usertable.userid = memberdetail.memberid AND memberdetail.memberid = (SELECT memberid FROM memberdetail WHERE email = ?)', "".$email. "'"));

    $reset = new Application_Model_DbTable_Register();
    $reset->resetPass($userid);

    $pswd = new Application_Model_DbTable_Register();
    $pswd = $pswd->getTemp();

    $mail = new Zend_Mail();

    $mail->setFrom('swap.test@yahoo.com.sg', 'Inexorable Beauty');
    $mail->addTo($email, $email);
    $mail->setSubject('Inexorable Beauty: Password Reset');
    $mail->setBodyText('Dear Customer,

            You have requested to reset your password.
            This is the temporary password: '.$pswd.'

            Please log in immediately and change your password.
            Thank You.

            Yours Sincerely,
            Inexorable Beauty');

    $mail->send();

    if($mail->send())
    {
        echo "Email successfully sent!";
    }
    else
    {
        echo "Email was not sent";
    }



}

我正在尝试获取从 memberid 引用的用户 ID。我可以通过 $_POST['email'] 的电子邮件获取 memberid。问题是,我似乎无法获得用户 ID 的值。我试图通过一个while循环来回显用户ID,但它不起作用。当我打印 SQL 时,它似乎与我写的语句不同。

4

1 回答 1

1

尝试像这样运行查询:

$email = $_POST['email'];
$subquery = $db->select()
               ->from('memberdetail', array('memberid'))
               ->where('email = ?', $email);

$select = $db->select()
             ->from('usertable', array('userid'))
             ->join('memberdetail', 'usertable.userid = memberdetail.memberid')
             ->where('usertable.userid = ?', $subquery);

$result = $select->query()->fetch();
if (!$result) {
    // user not found
} else {
    $userid = $result['userid'];
}

您现在拥有的方式$userid只是一个Zend_Db_Select对象,但从未执行过任何查询。此外,您不会将任何参数传递给select(),在方法中指定您想要的列from()

于 2012-08-11T21:39:49.303 回答