PM SYSTEM - 我无法打开特定的消息

时间:2013-12-26 00:06:35

标签: php mysql

我是php语言的新手。有人能帮助我吗?我用一个mysql平板电脑制作了个人信息系统。 mysql正在工作。我的收件箱正在工作,我可以看到我的消息。但是当我点击一条消息时,总是第一个消息竞赛开始。我怎样才能打开特定的消息? 这些是我的代码:

inbox.php

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

// get the messages from the table.
$get_messages = mysql_query("SELECT message_id FROM messages WHERE to_user='$username' ORDER BY message_id DESC") or die(mysql_error());
$get_messages2 = mysql_query("SELECT * FROM messages WHERE to_user='$username' ORDER BY message_id DESC") or die(mysql_error());
$num_messages = mysql_num_rows($get_messages);
// display each message title, with a link to their content
echo '<ul>';
for($count = 1; $count <= $num_messages; $count++)
{

    $row = mysql_fetch_array($get_messages2);
    //if the message is not read, show "(new)" after the title, else, just show the title.
if($row['message_read'] == 0)
{
    echo '<a href="read_message.php?messageid=' . $row['message_id'] . '">' . $row['message_title'] . '</a>(New)<br>';
}else{
echo '<a href="read_message.php?messageid=' . $row['message_id'] . '">' . $row['message_title'] . '</a><br>';
}}
echo '</ul>';
echo '<form name="newmsgfrm" method="post" action="new_message.php">';
 echo '<input type="submit" value="Send a New Message">';
 echo '</form>';

echo '<form name="backfrm" method="post" action="index.php">';
 echo '<input type="submit" value="Back to Home">';
 echo '</form>';
?>

read_message.php

<?php



// Connecting, selecting database
$link = mysql_connect('host', 'user', 'pass')
    or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('db') or die('Could not select database');


// Performing SQL query
$query = "SELECT * FROM messages WHERE to_user = '$username' " ;
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML

$row = mysql_fetch_array($result) or die(mysql_error());
echo $row['from_user'];
echo $row['message_title'];
echo $row['message_contents'];
 ?>

使用read_message.php我可以阅读我的消息,但只是第一个:/我该怎么做才能阅读特定消息?谢谢你的帮助:)(对不起我的英文..)

(我想我必须对消息ID做一些事情,但我不知道:/)

1 个答案:

答案 0 :(得分:0)

read_message.php需要使用messageid参数来读取请求的特定消息:

$messageid = sprintf("%d", $_GET['messageid']);

$query = "SELECT * FROM messages WHERE to_user = '$username' AND message_id = $messageid" ;