Hi I am a sixth form computing student making a website for coursework. It involves a basic messaging system that retrieves all messages from a database that is sent to the users id. I have made an algorithm that creates a table to display all the results however there is one flaw that I cannot solve. Along with the senders name, there is a hyperlink that goes to person.php - a page that displays other users profiles. It works like a template which is filled by the users information on the database. To get the other users information I am using sessions. $_SESSION['userid2'] is what holds the userid of the latest viewed person. However when the while statement loops again, userid2 is rewritten to the id of the person who sent the latest message. This means when you click on any name it sends you to person.php, but it will load the profile of the last person to send a message. To get around this I have tried making different variable names for each message but the problem with this is retreiving the name of the variable when clicked. I have also tried using functions and onClick() but all is to no prevail. Could an array work? Or any other php functions? Please feel free to ask any questions and any help is greatly appreciated. The loop is written bellow.
<?php
$n=0;
echo "<table width='1350' border='0' align='center'><br>";
echo "<tbody><br>";
echo "<tr><br>";
echo "<td width='200' bgcolor='#35312f' align='center' valign='middle'>Date</td><br>";
echo "<td width='200' bgcolor='#35312f' align='center' valign='middle'>Name</td><br>";
echo "<td width='950' bgcolor='#35312f' align='center' valign='middle'>Contents</td><br>";
echo "<tr>";
while ($n < $num_rows) {
mysqli_data_seek($result, $n);
$data = mysqli_fetch_assoc($result);
echo "<tr><br>";
echo "<td bgcolor='#35312f'>".$data['date']."</td><br>";
echo "<td bgcolor='#35312f'><a href='person.php'>".$data['firstname']." ".$data['secondname']."</a></td><br>";
echo "<td bgcolor='#35312f'>".$data['contents']."</td><br>";
echo "</tr><br>";
$n = ($n + 1);
}
echo "</tbody><br>";
echo "</table><br>";
?>