I have a form where I have individual textboxes on-screen where I want to insert a pupil name into each one. Each textbox will contain one pupil name. I have an SQL query that gets all the pupils I want for the class this form is created for. When the SQL is run in PHPMyAdmin, the query returns the exact values I want.
The code below is what I had hoped would be to get the data from the database and put it into an array so that I could put each row into a textbox later. However when I run this code, the finished array only contains 1 element and is the second row found by the query. The records found by query are;
+--------------------------+
| Pupil_Name (Column name) |
+--------------------------+
| Sam Price |
| Keith mcgareth |
+--------------------------+
Only Keith mcrgareth is echoed at the end. When both records should be echoed.
$pupilarray = array();
$pupilquery = mysqli_query($connection, "SELECT Pupil_Name FROM tbllogin WHERE Class_Name = 'Heulog' AND Access_Level = 'pupil'");
while($row = mysqli_fetch_assoc($pupilquery)){
$pupilarray = $row['Pupil_Name'];
}
echo $pupilarray;
Have I created my array wrong? or am I missing something?