Jump to content

problem with session variable and while loop


steviecee

Recommended Posts

I'm trying to work out a way to do the following, and I'm stumped! I'm querying a database and I'm using a while loop to display the data, at the end of every run through of the while loop I'm saving one of the returned fields in a session variable, to be passed to another page. The problem is that the session variable always sets itself to the value of the last run through, so it just passes one value to the next page, how can I set it up to pass all the values through?
code is:

[code]
$result = mysqli_query($conn, "select * from pm where userToID = 'steviece'");

while ($row = mysqli_fetch_array($result))
{
    echo "<tr>";
echo "<td>".$row['pmID']."</td>";
echo "<td>".$row['pmTopic']."</a></td>";
echo "<td>".$row['userID']."</td>";
echo "<td>";
$pmID = $row['pmID'];

session_start();
$_SESSION["messID"] = $pmID;
echo "<a href='viewMess.php'>View Message</a>";

echo "</td>";
echo "</tr>";
}
[/code]

Cheers
Steve
Actually the above question isn't strictly right. the session variable needs to pass the data of whatever row is selected, so if someone clicked the second row of the the table that data would be sent via the session variable  ::)

Cheers Steve

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.