Maybe I'm going about this the wrong way then.
Essentially what I have is a list of Databases in the original array, which are split up into 4 groups.
I then wanted to use those 4 groups to create 4 tables, which I could then use a javascript function to hide and show the rows of each table in turn.
I have managed to achieve this aim, but I have had to do it creating 4 distinct parts:
e.g.
Code: Select all
$sqDB1 = "";
$sqDB2 = "";
$sqDB3 = "";
$sqDB4 = "";
foreach($ss as $dbs) {
foreach($dbs as $dbg) {
if ($dbg['dbGroup'] == 1) {
if ($dbg['IO'] == "No" || $dbg['SQL'] == "No") {
$sqCol1 = "#$c7";
if ($sqDB1 == ""){$sqDB1 = $dbg['database'];}else{$sqDB1 = $sqDB1.",".$dbg['database']; }
}
}else if ($dbg['dbGroup'] == 2) {
...
}else if ($dbg['dbGroup'] == 3) {
....
}else if ($dbg['dbGroup'] == 4) {
.....
}
}
};
if ($sqDB1 == ""){
$sqDB1 = "All OK";
$sqDBArray1[0] = "All OK";
$sqDBArray1[1] = "All OK";
$sqCol1 = "#$c2";
$sqDB1C = 0;
}else{
$sqDBArray1 = explode(',',$sqDB1); //Create a PHP array
$sqDB1C = count($sqDBArray1);
if ($sqDB1C == 1 ) {array_push($sqDBArray1,$sqDB1);};
};
//REPEAT THE ABOVE SECTION 4 TIMES WITH $sqDB2, $sqDB3 etc.
Code: Select all
<script language="javascript">
//HIDE ALL THE ROWS
function hideRows()
{
var a = document.getElementById("dbTable1");
var len = a.rows.length;
for(i=1 ; i< len; i++)
{
a.rows[i].style.display = 'none';
}
//REPEAT 4 TIMES FOR dbTable2, dbTable3 etc.
}
//SHOW EACH ROW
var a = 1;
var b = 1;
var c = 1;
var d = 1;
function showRows()
{
var e = document.getElementById("dbTable1");
var len = e.rows.length;
e.rows[a].style.display = 'block';
a=a+1;
if(a==len)
{
a=1;
};
//REPEAT 4 TIMES FOR dbTable2, dbTable3 etc.
}
//TIMER
function hideShow()
{
hideRows();
showRows();
}
</script>
Code: Select all
<div style="position:absolute; left:0%; top:50%; display:block;">
<?php
print " <table id=\"dbTable1\" class=\"Round\" style=\"width:280px; position:relative; background-color:$sqCol1; padding:2px; z-index:2; display:block;\">\n";
print " <tr $hcol>\n";
print " <th class=\"RoundTop\">GROUP1 ( $sqDB1C )</th>\n";
print " </tr>\n";
$a = 0;
foreach($sqDBArray1 AS $sq){
if($a == 1){$disp = 'block';}else{$disp = 'none';}; //INITIAL DISPLAY STATUS
print " <tr id=\"$a\" style=\"display:$disp;\">\n";
print " <th class=\"RoundBottom\" style=\"vertical-align:middle; width:280px; height:50px;\">";
print $sq;
print " </th>\n";
print " </tr>\n";
$a++;
};
print " </table>\n";
?>
//REPEAT THIS 4 TIMES FOR dbTable2, dbTable3, etc.
</div>
It works, but to me it looks very messy, and I'm sure there must be a better option. Any hints would be appreciated.