Jump to content

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>';
}

?>

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.