Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2016
    Thanked 0 Times in 0 Posts

    Is it bad to compile all user messages into one table?

    I have a forums site I am creating with PHP and SQL.

    I am thinking about compiling all user messages into one table called user_messages

    It would be like:

    $senderId = 2;
    $recipientId = 3;
    $userMessage = "Hey, how's it going my friend?!";
    $postedOn = date('m-d-y');
    $insertMessage = $conn->prepare("
    INSERT INTO user_messages(user_sender_id, user_recipient_id, user_message, posted_on)
    VALUES(?, ?, ?, ?)
    $insertMessage->bind_param("iiss", $senderId, $recipientId, $userMessage, $postedOn);
    $userId = 12;
    $getMessages = $connect->prepare("SELECT * FROM user_messages WHERE user_recipient_id = ?");
    $getMessages->bind_param("i", $userId);
    $getMessagesResults = $getMessages->get_result();
    if($getMessagesResults->num_rows == 0) {
    print("No messages exist.");
    $messageTitle = $row['message_title'];
    Last edited by Hjb1694; Aug 11th, 2017 at 01:51 PM. Reason: added more code

  2. #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Denver, Colorado USA
    Thanked 552 Times in 537 Posts
    Yes, you would store all user messages in one table. What other method were you considering?

    BTW - your posted_on date column needs to be a DATE data type and use a YYYY-MM-DD format, so that you can do sorting/date-comparisons on the values. The format you have now, in a text/character column, cannot be directly sorted or compared by magnitude, and also takes more storage than a DATE data type.
    Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts