Jump to content

database query results in a 4 x 4 grid instead of rows?


fj1200

Recommended Posts

I'm trying to modify an existing and very useful and important app I wrote a year ago that checks the presence of several servers around the country and verifies ftp is running on each every 2 minutes.  Results are displayed on a php page - if a server does down the row goes red and sends the IT guys at the site and me an email.  Ok if you're sitting in front of the monitor, but I want a graphical version for display on a large screen.  I want to display large 2 icons in each table cell, one for a ping response and one for ftp status.  for both, a value of '0' is live, '1' is down.  For ftp I'm using ncftpput as it's exit codes are well documented and I can display the reason on screen.

 

How do I get the results into columns - say - 3 servers for one site, 4 for a 2nd and 3rd, and 2 for a 4th site so it's consistent and easy to follow?  Been hurting my head on it all morning!  I'm ok with php but this is challenging me a touch.

 

I want something like:

 

EXTERNAL SERVERS        |        INTERNAL SERVERS

SITE 1    |    SITE 2          |        SITE 3    |    SITE 4

 

  x  x              x  x                          x    x            x    x

  x  x              x  x                          x    x            x    x

  x  x              x  x                                              x    x

  x  x              x  x

 

Where X is a graphic of a light.  Pretty - but it works very well and is highly visible.  I eventually want an audible warning when 2 of the external servers go down.

 

Each X is a different server, in 2 groups at 4 sites.

 

At the moment, it works but I get one whole row of icons for each server.  Pages of them!  AArrgghh!

 

Any ideas?  There's probably a simple way of doing it but I can't see it!

 

<EDIT>

Is there a way to make a row or icon flash?  refresh the colour every 2 seconds or something?

 

You want something like

 

$i = 0;

//query

echo "<table>
<tr>
<td colspan=2>
External Servers
</td>
<td colspan=2>
Internal
</td>
</tr>
<tr>

<td>
Site1
</td>
<td>
Site 2
</td>
<td>
Site3
</td>
<td>
Site 4
</td>
</tr>
";

while($row=mysql_fetch_array(query))
{
echo "<td>" . $row['x'] . "</td>";

if($i == 4)
	{
	echo "</tr><tr>";
	$i = 0;
	}
else
	{
	$i ++;
	}
}

echo "</tr></table>";

 

 

Well you get the general idea. Try it. Change the $i setting if you're getting the wrong amount of cols

you should check jquery, prototype(scriptacoulous) or dojo for this kind of flashing icons and effects.

 

I guess you have to use double loops something like this may help you:

 

for ($i = 0 ;$i < count($server_list); $i++) {
  echo '<tr>';
  for ($j = 0 ; $j < 4; $j++) {  //Instead of 4 put max col number for a row.
    if ($server_list[$i+$j+1]) {
      echo '<td>' . $server_list[$i+$j] . '</td>';
    } else { //If the next one does not exists put a col with left of col number
      echo '<td colspan="' . 4 - $j . '"'>;
    }
  }
  echo '</tr>';
}

 

Something like this might help you I guess.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.