【发布时间】:2012-01-18 04:57:02
【问题描述】:
我对以下代码有一点问题:
<?php
class appointments
{
private $conn;
function __construct($conn)
{
$this->conn = $conn;
}
function usercompany($uid)
{
return $this->conn->getone("SELECT company FROM signup WHERE UID = '".$uid."'");
}
function hastemplate($uid)
{
return $this->conn->getone("SELECT COUNT(parentid) FROM appointments_templates WHERE parentid = '$uid'");
}
function gettemplate($uid)
{
if($this->hastemplate($uid)){
return $this->conn->getrow("SELECT * FROM appointments_templates WHERE parentid = '" . $uid . "'");
} else {
$appointment_template = 'This is a reminder to let you know that you have an appointment on {appointment} at '. $this->usercompany($uid);
$sql = "INSERT INTO appointments_templates SET parentid = '" . $uid . "', content = '" . $appointment_template . "'";
$this->conn->execute($sql);
return $this->gettemplate($uid);
}
}
}
?>
当我自己调用usercompany($uid) 时,我得到一个正确的结果,即用户公司。然而,当我调用gettemplate($uid) 时,新模板被添加到数据库中,但没有usercompany($uid) 的结果。我做错了吗?
编辑:关于 INSERT 语法:http://milov.nl/2836
回顾一下:问题不在于它没有被添加到数据库中,而是被插入为“这是一个提醒,让您知道您在 XYZ 的 {appointment} 有一个约会公司”它被添加为“这是一个提醒,让您知道您在 {appointment} 上有一个约会”
【问题讨论】:
-
能把使用这个类的代码放上来吗?