I have a DB with a table full of facility names. I am trying to output the facilities alphabetically by facility name + display the account that it is associated with.
Facilities table looks something like this:
id | account_id | facility_name |
2 | 2 | Facility A |
3 | 2 | Facility B |
4 | 2 | Facility A |
Accounts table looks like this:
account_id | account_name |
1 | Account 1 |
2 | Account 2 |
3 | Account 3 |
And I am trying to get my output to be like this:
facility_name | account_name |
Facility A | Account 1 |
Facility B | Account 1 |
I am outputting this into a table using PHP so here is kinda what it looks like:
$sql = "SELECT * FROM facility INNER JOIN account ON account.account_id = facility.account_id WHERE facility.account_id = '". $q ."' ORDER BY 'facility_name'";
echo "<table>
<tr>
<th>Facility Name</th>
<th>Account Name</th>
</tr>";
while ($row = mysqli_fetch_array($data)) {
echo "<tr>";
echo "<td>" . $row['facility_name'] . "</td>";
echo "<td>" . $row['account_name'] . "</td>";
echo "</tr>";
}
echo "</table>";
However this does not seem to be ordering my table my facility name, it is just outputting in the order that it was input in.
How can I output my data so that it is also ordered by 'facility_name'?