Jump to content

[SOLVED] Private Message System Question


graham23s

Recommended Posts

Hi Guys,

 

just a question i have in regards to a private messaging system for  asite, i have done a few, but i always do 2 tables:

 

private_messages

private_messages_sent

 

but on a scripts i downloaded in the mysql schematics there was only 1 table:

 

messages

 

with:

 

CREATE TABLE `messages` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `sender` int(10) unsigned NOT NULL default '0',
  `receiver` int(10) unsigned NOT NULL default '0',
  `added` datetime default NULL,
  `msg` text,
  `unread` enum('yes','no') NOT NULL default 'yes',
  `poster` bigint(20) unsigned NOT NULL default '0',
  `location` enum('in','out','both') NOT NULL default 'in',

 

so i could have gotten away with doing just 1 table instead of the 2, or is it better the way i was doing it (probably not lol)

 

cheers guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/51878-solved-private-message-system-question/
Share on other sites

Well...you don't really need another table to be able to tell the user what messages they have sent. Just do a query that will pull the messages they have sent by matching their ID with the "sender" field.

 

<?php

$sql = mysql_query("SELECT * FROM messages WHERE sender='$user_id'");

echo 'You have sent the following messages...<p>';

while ($row = mysql_fetch_assoc($sql)){
   echo $row['message'].'<br>';
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.