2012-01-06 235 views
-1

我想在會議結束後7天輸出一些會議記錄。我只在以下代碼中插入了一條致命錯誤消息。SQL錯誤:'致命錯誤'

<?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是在$結果查詢。

有人嗎?

回答

1

「$ this」在類中用於引用自身。由於你不在課堂內,php腳本會產生錯誤。使用的mysql_query()代替,當然你需要連接到數據庫第一

1

您在代碼的第5行使用$this->db,它不是對象上下文。你可能想使用$db,但你也需要在$db變量上啓動db連接才能工作。

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')