Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

messaging system

$
0
0

Im trying to create a message system

 

my database field has userid, receiveid, username, receivename, message, date, read

 

userid is the id of the person sending the message

receiveid is the id of the person receiving the message

 

username is the name of the senders name

recievename is the name of the person receiving the message

 

message is the message

date is the date sent

 

read is always set as no but will be set as yes when someone access the message.

 

this is my code so far

$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$pages = implode(mysql_fetch_assoc(mysql_query("SELECT COUNT(id) FROM imessages")));
$pages = ceil($pages / 15);

$querystring = "";
foreach ($_GET as $key => $value) {
	if ($key != "page") $querystring .= "$key=$value&";
}

echo "Pages: ";
for ($i = 1; $i <= $pages; $i++) {
	echo "<a " . ($i == $page ? "class=\"selected\" " : "");
	echo "href=\"?{$querystring}page=$i";
	echo "\">$i</a> ";
echo "<p><b>Inbox</b> | Recieved Messages :: <a href=http://www.sentuamessage.com/inbox.php?action=sentmessages>Sent Messages</a></p>";
}

$result = mysql_query("SELECT * FROM imessages where recieveid='$row[id]' order by date ASC LIMIT " . (($page - 1) * 15) . ", 15");
while($news = mysql_fetch_array($result))
{
$position=500;
 $message="$news[message]"; 
 $post = substr($message, 0, $position);

echo "<table border=0 width=100% cellspacing=0 cellpadding=0>
	<tr>
		<td>
		<table border=0 width=100% cellspacing=0 cellpadding=0>
			<tr>
				<td>
				<table border=0 width=100% cellspacing=0 cellpadding=0>
					<tr>
						<td>
						<table border=0 width=100% cellspacing=0 cellpadding=0>
							<tr>
								<td width=29> </td>
								<td width=27><img src=http://www.sentuamessage.com/commentsavatar.jpg></img></td>
								<td width=27> </td>
								<td>";
echo utf8_encode($post);
echo "...";
echo "</td>
							</tr>
						</table>
						</td>
						<td width=10> </td>
					</tr>
					<tr>
						<td><p align=right><font size=2><b><a href=http://www.sentuamessage.com/profile.php?who=$news[recieveid]>$news[recievename]</a></b></font></p></td>
						<td width=10> </td>
					</tr>
				</table>
				</td>
				<td width=10 bgcolor=#008000> </td>
				<td width=31> </td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td> </td>
	</tr>
</table>";
}
echo "Pages: ";
for ($i = 1; $i <= $pages; $i++) {
	echo "<a " . ($i == $page ? "class=\"selected\" " : "");
	echo "href=\"?{$querystring}page=$i";
	echo "\">$i</a> ";
}

I want this to be my inbox, it would work like facebook, where it shows the latest message from the person in the conversation, so if I had 5 messages off 1 user it only shows the latest one and not the other 4.

 

When you access the most recent message then you can see the history of your chat with that user.

 

How can I do this, what would be the best possible way?


Viewing all articles
Browse latest Browse all 13200

Trending Articles