Hi I'm trying to write an SQL statement to populate a table but I keep getting an error:
Undefined index: st.Name, and Undefined index: s.Name.
I don't get why I'm getting that because I have selected them in the SQL statement. I'm not very good at SQL so help would be appreciated.
<?php
ini_set("display_errors", 1);
try{
$stmt = $conn->prepare(
"SELECT st.Name, s.Name
From Sports AS s INNER JOIN Choices AS c
ON s.Sport_ID = c.Sport_ID INNER JOIN Student_Choices AS sc
ON sc.T1_Choice = c.Choice_ID INNER JOIN Students AS st
ON st.Username = sc.Username
");
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo '<tr>
<td>'.$row['st.Name'].'</td>
<td>'.$row['s.Name'].'</td>
</tr>
';
}
}
catch(PDOException $e)
{
echo "error".$e->getMessage();
}
?>