Jump to content

Archived

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

RTS

Read Messages

Recommended Posts

I have a page that retrieves four colums ('ID', 'Sender', 'date', 'subject') I need to have it so that when you click the a link to a page called read.php, it gets the mesage ID from the database where the ID equals the message you clicked next to. here is what I have so far:
messages.php:
[code]<?php
$user = $_SESSION['username'];
$con = mysql_connect("localhost","ZackBabtkis","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("test", $con);
$result = mysql_query("SELECT * FROM messages WHERE username = '$user'");
echo "<table border='1' width=728>
<tr>
<th>ID:</th>
<th>From:</th>
<th>On:</th>
<th>Subject:</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr><td width=200>";
  echo $row['ID'];
  echo "</td><td>";
  echo $row['Sender'];
  echo "</td><td>";
  echo $row['Date'];
  echo "</td><td>";
  echo '<a href=read.php>';
  echo $row['Subject'];
  echo '</a>';
  echo "</td><td>";

  }
echo "</table>";

mysql_close($con);
?>[/code]

Share this post


Link to post
Share on other sites
[code=php:0]
echo '<a href="read.php?id='.$row['ID'].'">';
[/code]

then on read.php, you would run a query soemthing like....

[code=php:0]
$sql = "SELECT * FROM tbl WHERE ID=".$_GET['id'];
[/code]

Share this post


Link to post
Share on other sites

×

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.