I have the following code, which I've used a variation of elsewhere on my project and it works everywhere else, but not in this case.
$pdo = new PDO('sqlsrv:server=localhost;Database=db', 'root', 'password');
$getResultsInst = $pdo->query("SELECT distinct [names], [id] FROM [tblStaff] ORDER BY [names] asc");
while ($result = $getResultsInst->fetch(PDO::FETCH_ASSOC)) {
$names = "<tr>
<td>".$result['names']."</td>
<td>Test</td>
</tr>";
}
When I run that query in SQL Server management studio is returns a lot more than 1 row, but when I run this code in the HTML...
<table class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>ID</th>
</tr>
</thead>
<tbody>
<?php echo $names;?>
</tbody>
It just returns the last row of the SQL query, I can't figure out why, as I've used this while loop elsewhere and it creates a new row for each fetched result.