Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2014
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    mark read/unread message in php

    hi, i am developing messaging system in php. i am able to retrieve messages stored in mysql but not able to mark unread message in bold

    this code will retrive data from mysql table and display result in table format.
    I want unread message to be shown in bold letter and read message in normal text.

    In my table i have msg_read column which is set to '0' if message is unread and '1' if message is already read by user.

    echo "<table border='1' cellpadding='10'>";
    echo "<tr><th>From</th> <th>Subject</th> <th>Date</th></tr>";
    // loop through results of database query, displaying them in the table

    while($row = mysqli_fetch_array($selectresult))
    {
    // echo out the contents of each row into a table

    echo "<tr style=''>";
    echo '<td>' . $row['from_user'] . '</td>';
    echo '<td>' . $row['message_title'] . '</td>';
    echo '<td>' . $row['date'] . '</td>';
    echo '<td><a href="?page_id=1174&MI=' . $row['message_id'] . '">Read</a> </td>';
    echo '<td><a href="?page_id=1301&MI=' . $row['message_id'] . '">Delete</a> </td>';
    echo "</tr>";


    }


    // close table>
    echo "</table>";

    Please if someone can help Thank You.

  • #2
    Regular Coder
    Join Date
    Sep 2011
    Posts
    408
    Thanks
    18
    Thanked 26 Times in 26 Posts
    Not sure if it matters but you should keep the echo's with single quotes throughout the whole time and use double quotes for html attributes, just to keep it all similar and easier to manage.

    Now about the styling. Simply add a check for the table row and add a custom css class/style rule based on it.

    Example:
    PHP Code:
    echo '<table border="1" cellpadding="10">';
    echo 
    '<tr><th>From</th> <th>Subject</th> <th>Date</th></tr>';
    // loop through results of database query, displaying them in the table

    while($row mysqli_fetch_array($selectresult))
    {
    // echo out the contents of each row into a table
    echo '<tr style="'.($row['read'] ? 'font-weight:bold;' '').'">';
    echo 
    '<td>' $row['from_user'] . '</td>';
    echo 
    '<td>' $row['message_title'] . '</td>';
    echo 
    '<td>' $row['date'] . '</td>';
    echo 
    '<td><a href="?page_id=1174&MI=' $row['message_id'] . '">Read</a> </td>';
    echo 
    '<td><a href="?page_id=1301&MI=' $row['message_id'] . '">Delete</a> </td>';
    echo 
    "</tr>";
    }

    // close table>
    echo "</table>"
    The ? and : is simply this in other terms:
    PHP Code:
    if($row['read'])
        
    'font-weight:bold';
    else
        
    ''
    The difference is the ? : method can be used in strings.
    Last edited by Dubz; 05-16-2014 at 10:20 AM.
    If I've helped you out, show your appreciation by clicking the "Thanks" link as well as a link below!

    AdFly
    Facebook | Twitter
    Google | YouTube

  • Users who have thanked Dubz for this post:

    saurabh_moses (06-02-2014)

  • #3
    New to the CF scene
    Join Date
    May 2014
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi Dubz,
    Thanks for the help.
    i use your code it is working. but it is showing all read message as bold and unread message as normal text.?

  • #4
    Regular Coder
    Join Date
    Sep 2011
    Posts
    408
    Thanks
    18
    Thanked 26 Times in 26 Posts
    My bad, had it backwards, just switch the strings around and it'll be fixed. I think I was thinking unread rather than read
    If I've helped you out, show your appreciation by clicking the "Thanks" link as well as a link below!

    AdFly
    Facebook | Twitter
    Google | YouTube


  •  

    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
    •