Jump to content

messaging system


Lone_Ranger
Go to solution Solved by Lone_Ranger,

Recommended Posts

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?

Link to comment
Share on other sites

I figured out a work around to my own answer without using AJAX.

 

Only problem I am having now is if I'm doing a MYSQL query and have where item=item && item2=item2 I keep getting a Boolean error when uploaded. Quite annoying why would this be?

 

in this case for an example a count MySQL query where a row = user id && read = no it would come back with a boolean

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.