I have an SQL table (Children):
ID | Name
----------------
I03 | Lucy
I05 | Jade
I06 | Jason
I am trying to create a table in PHP which only displays the name in each row, so the table has one column only. I would like each name to have a hyperlink to this page: http://localhost/Child_Stats.php?(x)
'x' must be the child id.
So, e.g. when clicking on Lucy, the hyperlink is: http://localhost/Child_Stats.php?'I03'.
This is my code so far:
$c = mysql_connect("localhost", "root", "password");
if (!$conn) {
die("Unable to connect: ". mysql_error());
}
mysql_select_db("table", $conn);
$query = "SELECT * FROM Children";
$data = mysql_query($query, $conn);
echo "<table border = 1>
<tr>
<th>Child</th>
</tr>";
while($record = mysql_fetch_array($data)){
echo "<tr>";
echo "<td><a href='http://localhost/Child_Stats.php?'".$record['ID']."''>".$record['Name']."</a> </td>";
echo "</tr>";
}
echo "</table>";
mysql_close($conn); //close connection
My code doesn't work because which ever child I select, in the table, the hyperlink is always 'http://localhost/Child_Stats.php?'. The ID for each specific child isn't appended to it.