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?

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.