Reputation: 95
So I'm having trouble figuring out how to show a link to a new page based on ID. I've created a review page of all timecards submitted based on employee. It works fine, but in case the employee wants to review an individual record and change specific things in the record is where i'm having trouble with. Below is a snippit of code i'm using to display the information. Because the timecard has MANY fields in I don't need to waste the whole page showing all the information until the employee actually submits the specific card he wants.
$result = mysql_query("SELECT ID,employee,date FROM tcardsubmit WHERE employee = '$empname");
echo "<table border='1'>
<tr>
<th>ID</th>
<th>EMPLOYEE NAME</th>
<th>DATE</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['employee'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "</tr>";
}
echo "</table>";
That query shows all I really need the employee to see. What i'd like is for the ID number to carry over to a page called 'review.php' but the ID number carries over with it, then I can just use GET ID and pull all the data based on the ID on the review page. Any suggestions?
Upvotes: 2
Views: 1322
Reputation: 6122
In the loop add another column and do
echo '<td><a href="review.php?id=' . $row['ID'] . '">View</a></td>';
In review.php
$id = (int) $_GET['id'];
And query..
SELECT <fields> FROM tcardsubmit WHERE ID = $id
Make sure to escape id .. I did it by casting to an int, but you can also do mysql_real_escape_string
Upvotes: 1
Reputation: 3620
make a little change on your table
echo "<table border='1'>
<tr>
<th>ID</th>
<th>EMPLOYEE NAME</th>
<th>DATE</th>
<th>ACTION</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['employee'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td><a href=review.php?ID=" . $row['ID'] . ">Review</a></td>";
echo "</tr>";
}
echo "</table>";
Upvotes: 1