Hi guys, come across a little problem here. I receive data from an sql query.
$sql = "SELECT s.ship_id, s.ship_letter, s.availability, s.last_updated, a.ship_alert
                      FROM ship_data s
                      JOIN fleet_data h
                          ON s.ship_id = h.id
                          ORDER BY ship_id, `last_updated` DESC";
So that pretty much provides me with all the data I need. Because I needed this displayed in a certain way, I had to do a lot of work. I started by getting the data

$letters = array();
$data = array();

while ($row = mysql_fetch_assoc($query)) {
	$dateString = date("Y-m-d H:i:s", strtotime($row["last_updated"]));
	$data[$row["ship_id"]][$dateString][$row["ship_letter"]] = $row["availability"];

	if (!array_key_exists($row["ship_id"], $letters)) {
		$letters[$row['ship_id']] = array();
	if (!in_array($row['ship_letter'], $letters[$row['ship_id']])) {
		$letters[$row['ship_id']][] = $row['ship_letter'];
Then I had to display the data within a table, a certain way like so
foreach($data as $sid => $ship_data){
	echo "<table class='ship_table'><tr><th>";
	echo "Ship ".$sid."</th>";
	foreach($letters[$sid] as $letter){
		echo "<td>".$letter."</td>";
	echo "</tr>";
	foreach($ship_data as $time => $row){
		$time = date("d/M/Y H:00", strtotime($time));
		echo "<tr>";
		echo "<td class='time_row'>{$time}</td>";
		foreach($row as $cell){
			$className = $cell > 0 ? "green" : "red";
			echo "<td class='number_row {$className}'>$cell</td>";
		echo "</tr>";
	echo "</table>";
So everything works great and displays how I need it too. The last part I am having trouble with is getting 1 a.ship_alert displayed for each ship. Ideally, I would like to display it after echo "Ship ".$sid."</th>";

So with the ship_alert, should I add it to my multidimensional array, maybe like
$data[$row["ship_id"]][$dateString][$row["ship_letter"]][$row["ship_alert"]] = $row["availability"];
If so, how can I get access to it in my for loop above? $sid only produces one output per ship, I need the ship_alert to do the same. In other words I dont want this value produced for every row, just for every group (ship) of rows.

Sorry if I am confusing, getting slightly confused myself.

Cheers for the advice.