MikeS
MikeS

Reputation: 383

Better way of storing "messages" data in MySQL using PHP

I'm building a website that has a user messaging system. I'm using MySQL to store every data. The inbox table is set up like this:

  `mid` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `to_uid` INT UNSIGNED NOT NULL ,
  `from_uid` INT UNSIGNED NOT NULL ,
  `content` TEXT(4000) NOT NULL ,
  `date` DATETIME NOT NULL ,
  `isvisible` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1 ,

I had the user-to-user messaging set up to use only characters and numbers so that's fine. What I'm trying to do are notification messages to the user. What's a good way to insert messages if they contain php variables and html? Here's where I am so far before inserting it.

$content = "".$username." is requesting to join your trip. Click <a href=\"browse.php?tid=D".$t_tid."\">here</a> to go to the trip.<button>here\'s a button</button>";

Is this the proper way? I'm just a beginner so anyone who could shed some light is greatly appreciated.

Upvotes: 0

Views: 110

Answers (1)

Shiplu Mokaddim
Shiplu Mokaddim

Reputation: 57650

I think you can add a column like this

`message_type` enum ('REQ_JOIN_GROUP', 'REQ_FRINDSHIP', 'REQ_TAG_APPROVE', 'MSG_PRIV', 'MSG_WALL', 'TAG_PHOTO', 'TAG_NOTE')
`message_param` varchar(20)

Depending on the message type you can just create the message.
For example.

  1. REQ_JOIN_GROUP:
    from_uid has requested to_uid to join group message_param
  2. REQ_FRIENDSHIP:
    from_uid has requested to make friendship with to_uid(you)
  3. REQ_TAG_APPROVE: from_uid has tagged to_uid(you) in message_param photo

Just normalize it.

Upvotes: 1

Related Questions