change colour of td based on other td
Posted: Mon Jul 26, 2010 11:13 am
Whilst, I'm sure this must be possible, I can't see how, any ideas appreciated...
I have a PHP script which runs a set of queries, against two MySQL databases, and presents them as a table. One is a master, the other a slave, the idea being to compare the number of entries in various tables.
What I was hoping to do is find a way to change the colour of a field if the slave doesn't match the Master. I've done this based on the content of the field, but can't see a way to do it by matching it against a different field.
I have a PHP script which runs a set of queries, against two MySQL databases, and presents them as a table. One is a master, the other a slave, the idea being to compare the number of entries in various tables.
Code: Select all
$u = "root";
$p = "xxx";
$p2 = "xxx";
$dbs = "dbname";
$connections_array[] = array('server' => '123.1.2.3:3306',
'user' => $u,
'password' => $p,
'database' => 'db Master');
$connections_array[] = array('server' => '123.1.2.4:3306',
'user' => $u,
'password' => $p2,
'database' => 'db Slave' );
$query_array[] = array('query' => "SELECT COUNT(*) FROM tab0");
$query_array[] = array('query' => "SELECT COUNT(*) FROM tab1");
$query_array[] = array('query' => "SELECT COUNT(*) FROM tab2");
$query_array[] = array('query' => "SELECT COUNT(*) FROM tab3");
$query_array[] = array('query' => "SELECT COUNT(*) FROM tab4");
$query_array[] = array('query' => "SELECT COUNT(*) FROM tab5");
?>
<!--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>db replication v1.0</title>
<link rel="stylesheet" type="text/css" href="db_Count.css" />
</head>
<body>
<div align="center">
<p class="heading">Results of db Replication</p>
<?php
echo "<p>";
$timezone = "Europe/London";
date_default_timezone_set ($timezone);
echo date('H:i:s');
echo "</p>";
echo "<table class=\"center\">";
echo "<tr class=\"hcol\"><th>DB Name</th>";
echo "<th>tab0</th>";
echo "<th>tab1</th>";
echo "<th>tab2</th>";
echo "<th>tab3</th>";
echo "<th>tab4</th>";
echo "<th>tab5</th>"</tr>";
for($i = 0; $i <sizeof($connections_array); $i++) {
$con = mysql_connect($connections_array[$i]['server'], $connections_array[$i]['user'], $connections_array[$i]['password']);
mysql_select_db($dbs, $con);
$dbName = $connections_array[$i]['database'];
echo "<tr><td>$dbName</td>";
for($q = 0; $q <sizeof($query_array); $q++) {
$result = mysql_query($query_array[$q]['query'], $con) or print("<p>ERROR:</p>".mysql_error());
if ( !$result ) { goto end;}
while($row = mysql_fetch_assoc($result)) {
foreach ($row as $attribute)
if ( is_null($attribute) )
{ print "<td> " ;
print "\n";
print "<br/></td>";
} else {
print "<td>{$attribute} " ;
print "\n";
print "<br/></td>";
}
}
}
echo "</tr>";
mysql_close($con); }
end:
echo "</table> </br>";
?>
</div>