2013-10-02 43 views
-2

這裏是我的「讀郵件」代碼...如何設置數據庫以標記已讀取的消息?

我想添加一個代碼,知道消息已讀或不...

<?php 
session_start(); 
$userfinal=$_SESSION['sessioname']; 
require "config.php"; 

$messageid = $_GET['messageid']; 
$message = mysql_query("SELECT * FROM messages WHERE message_id = '$messageid' AND to_user = '$userfinal'"); 
$message=mysql_fetch_assoc($message); 

echo "<h1>Title: ".$message['message_title']."</h1><br><br>"; 
echo "<h3>From: ".$message['from_user']."<br><br></h3>"; 
echo "<h3>Message: <br>".$message['message_contents']."<br></h3>"; 

echo '<form name="backfrm" method="post" action="inbox.php">'; 
echo '<input type="submit" value="Back to Inbox">'; 
echo '</form>'; 
?> 
+2

就在這個頁面上的某個地方添加更新查詢來改變'read'標誌'1'只要你有在外地'read'你'消息'表。 – Deepak

+0

將flag bool(讀取)添加到您的消息表中,並檢查如下內容: if(isset($ messageid)){//更新標誌爲1}; – RePRO

+1

請包括您嘗試的代碼(記錄「讀取」狀態)和出錯的地方。 – showdev

回答

0

那麼如果用戶到達這個他們已經閱讀了這封電子郵件。所以只需添加消息的更新tabele這個代碼:

<?php 
session_start(); 
$userfinal=$_SESSION['sessioname']; 
require "config.php"; 

$messageid = $_GET['messageid']; 
$message = mysql_query("SELECT * FROM messages WHERE message_id = '$messageid' AND to_user = '$userfinal'"); 
$message=mysql_fetch_assoc($message); 

// set message as read 
$result = mysql_query("UPDATE messages SET `has_been_read` = 1 WHERE message_id = '$messageid'"); 
if (!$result) { 
    // error updating the message to has_been_read 
    // This bit is up to you!!! 
} 


echo "<h1>Title: ".$message['message_title']."</h1><br><br>"; 
echo "<h3>From: ".$message['from_user']."<br><br></h3>"; 
echo "<h3>Message: <br>".$message['message_contents']."<br></h3>"; 

echo '<form name="backfrm" method="post" action="inbox.php">'; 
echo '<input type="submit" value="Back to Inbox">'; 
echo '</form>'; 
?> 
+0

你將會對使用不推薦使用的mysql_ *擴展名而不是新的PDO或mysqli使用感到嘮叨,並且正確如此。但是,傢伙,小步驟呃! – RiggsFolly

相關問題