0

Hello,

I am trying to create a web message features. This is the code that I have done so far:

messages.php

    <?php
                //LOAD INBOX MESSAGES

                $result = mysql_query("SELECT * FROM messages WHERE to_stu_username='".$_SESSION['username']."' ORDER BY date") or die(mysql_error());
                ?>
                <table id="admintable" border="1" cellpadding="2" cellspacing="0" width="900px">
                    <tr>
                    <b>Inbox</b><br><br>
                        <th>From</th><th style="width:500px;">Messages</th><th>Date</th>
                    </tr>
                    <?php
                    $i=0;
                    while ($data = mysql_fetch_array($result)){
                    $result2=($i%2)?'#DFA09D':'white';


                            echo "<tr bgcolor='$result2'>";                  
                            echo '<td>'.$data['from_stu_username'].'</td>';
                            echo '<td>'.$data['messages'].'</td>';                            
                            echo '<td>'.$data['date'].'</td>';
                            echo '</tr>';

                    $i++;   
                    }
                    ?>
                </table>

                <?php
                //LOAD OUTBOX MESSAGES

                $result = mysql_query("SELECT * FROM messages WHERE from_stu_username='".$_SESSION['username']."' ORDER BY date") or die(mysql_error());
                ?>
                <table id="admintable" border="1" cellpadding="2" cellspacing="0" width="900px">
                    <tr>
                    <br><br><b>Sent</b><br><br>
                        <th>To</th><th style="width:500px;">Messages</th><th>Date</th>
                    </tr>
                    <?php
                    $i=0;
                    while ($data = mysql_fetch_array($result)){
                    $result2=($i%2)?'#DFA09D':'white';


                            echo "<tr bgcolor='$result2'>";                  
                            echo '<td>'.$data['to_stu_username'].'</td>';
                            echo '<td>'.$data['messages'].'</td>';                            
                            echo '<td>'.$data['date'].'</td>';
                            echo '</tr>';

                    $i++;   
                    }
                    ?>
                </table>

One thing that I am trying to do right now is to create differentiation between new messages (unread) and old ones (read). How to do so? New messages should appears in bold font for example and the old ones in normal font color.

Any idea?

2
Contributors
1
Reply
10
Views
3 Years
Discussion Span
Last Post by Borzoi
0

You'll need an entry in the database which marks the message as read or unread. From your code, I can see that you only have four entries in the database: from_stu_username, to_stu_username, messages, date. Just add another column to hold the record of whether it is read and then mark the message as such if it is.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.