html table cell validation by mysql query results  | Member | | Join Date: Jan 2008
Posts: 56
| |
I have a table that I want a,b,c,d,e,f,g,h,and m for headers and 26 rows. In the values I want to verify against a mysql query. If cell A3 is in the list I want to highlight it yellow (or put an X for simplicity of the post). I can get the results in my table but it's not the correct layout. I'm also am unaware of how to validate for a cell that doesn't exist in the results and skip it so the correct cells are highlighted. Any help would be MUCH appreciated. This one's a little over my head. Thanks.
Here's my current code. - print "<table border=1>";
-
$x=0;$y = 1;
-
while ($y <= 26){
-
$z = 0;
-
print "<tr>";
-
while ($z <= 8){
-
$q = mysql_query("select concat(left(row,1), mid(row,3,2)) as 'binloc' from rows where done = true group by binloc") or die("unable to get query results");
-
mysql_data_seek($q,$x);
-
$row = mysql_fetch_row($q);
-
print "<td>".$row[0]."</td>";
-
$x++;$z++;
-
}
-
print "</tr>";
-
$y++;
-
}
-
print "</table>";
|  | Member | | Join Date: Jan 2008
Posts: 56
| | | re: html table cell validation by mysql query results
Here's what I came up with to get my values to test against the query results. (along with printing it out for clarity) - $alpha = array("A", "B", "C", "D", "E", "F", "G", "H", "M");
-
-
foreach ($alpha as $letter) {
-
for($j=1;$j <= 26;$j++){
-
print $letter.$j.", ";
-
}
-
print "<br />";
-
}
|  | Member | | Join Date: Jan 2008
Posts: 56
| | | re: html table cell validation by mysql query results
I guess this one wasn't over my head. Here's my solution: - $query = "select concat(left(row,1), mid(row,3,2)) as 'binloc' from rows where done = true group by binloc";
-
$results = mysql_query($query) or die("Couldn't execute query");
-
while ($row = mysql_fetch_row($results)){
-
$qyResults[] = $row[0];
-
}
-
-
$alpha = array("A", "B", "C", "D", "E", "F", "G", "H", "M");
-
print "<table border=1>";
-
-
for($j=1;$j <= 26;$j++){
-
print "<tr>";
-
foreach ($alpha as $letter) {
-
-
if ($j < 10) //because my list is a letter
-
{ //followed by a 2 digit number
-
$quadrant = $letter."0".$j;
-
}
-
else
-
{
-
$quadrant = $letter.$j;
-
}
-
if (in_array($quadrant,$qyResults))
-
{
-
print "<td>".$quadrant."</td>";
-
}
-
else
-
{
-
print "<td bgcolor='ffff00'>X</td>";
-
}
-
// print $quadrant." ";
-
-
}
-
print "</tr>";
-
}
-
print "</table>";
I had to push my query results into a php array, that made it a lot easier. This code will validate every cell against my list of completed cells and highlight the rest. Oh yeah, I also finally got the format correct so the rows are transposed. Just how I like it... Am I talking to myself?? :)
Edit:
If there is an easier or more standardized way of doing this please let me know. Thanks.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,223 network members.
|