SQL错误:'致命错误'

时间:2012-01-06 16:48:56

标签: php mysql date

我试图在会议开始后7天输出一些时间。我在以下代码中插入只是为了得到致命的错误消息。

 <?php
$id = $_GET['meeting_id'];
$from = date( 'Y-m-d', strtotime( $row['date_update'] . '-7 days' ) ); 

$result = $this->db->get ('SELECT * FROM Meetings INNER JOIN Minutes ON Minutes.meeting_id = Meetings.meeting_id WHERE Rooms.date >= "' . $from . '" AND Rooms.date <= NOW() AND Minutes.meeting_id = $id')

or die(mysql_error());

if (mysql_num_rows($result) == 0) {
       echo '<h3>There Arent Any Minutes For This Meeting Yet</h3>';
    } else {

while($info = mysql_fetch_array($result))
{
        echo "<tr>";
        echo "<td><br/>" .'Title: '. $info['title']." </td>";
        echo "<td><br/><br/>" .'Subject: '. $info['subject']. "</td>";
        echo "<td><br/><br/>" .'Next Subject: '. $info['next_subject']."</td>";

        echo '<br/><br/><a href="attendees.php?meeting_id=' . $info['meeting_id'] . '" target="_blank">Attendees</a>';
        echo '&nbsp;|&nbsp;<a href="apologies.php?meeting_id=' . $info['meeting_id'] . '" target="_blank">Apologies</a>';

        }
    }
echo "</tr>";
echo "</table>";
?>

我得到的错误信息如下:

Fatal error: Using $this when not in object context in E:\webareas\hj942\CW\meetings\conference\viewminutes.php on line 59

第59行是$ result的查询。

3 个答案:

答案 0 :(得分:1)

您在代码的第5行使用$this->db,而不是对象上下文。您可能希望使用$db,但您还需要在$db变量上启动数据库连接才能使用它。

答案 1 :(得分:1)

“$ this”在类中用于引用自身。由于您不在课堂内,因此php脚本会产生错误。请改用mysql_query(),当然您需要先连接到数据库

答案 2 :(得分:0)

首先,建立一个MySQL连接:

$db = mysql_connect('db_host', 'db_user', 'db_password');

然后,将$db变量与mysql_query()函数一起使用,而不是$this->db->get

$result = mysql_query($db, 'SELECT * FROM Meetings INNER JOIN Minutes ON Minutes.meeting_id = Meetings.meeting_id WHERE Rooms.date >= "' . $from . '" AND Rooms.date <= NOW() AND Minutes.meeting_id = $id')

甚至没有$db变量(如果只使用一个数据库):

$result = mysql_query('SELECT * FROM Meetings INNER JOIN Minutes ON Minutes.meeting_id = Meetings.meeting_id WHERE Rooms.date >= "' . $from . '" AND Rooms.date <= NOW() AND Minutes.meeting_id = $id')