By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,304 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,304 IT Pros & Developers. It's quick & easy.

html table cell validation by mysql query results

aas4mis
P: 97
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.
Expand|Select|Wrap|Line Numbers
  1.         print "<table border=1>";
  2.         $x=0;$y = 1;
  3.         while ($y <= 26){
  4.             $z = 0;
  5.             print "<tr>";
  6.             while ($z <= 8){
  7.                 $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");
  8.                 mysql_data_seek($q,$x);
  9.                 $row = mysql_fetch_row($q);
  10.                 print "<td>".$row[0]."</td>";
  11.                 $x++;$z++;
  12.             }
  13.             print "</tr>";
  14.             $y++;
  15.         }        
  16.         print "</table>";
Sep 18 '08 #1
Share this Question
Share on Google+
2 Replies


aas4mis
P: 97
Here's what I came up with to get my values to test against the query results. (along with printing it out for clarity)

Expand|Select|Wrap|Line Numbers
  1.         $alpha = array("A", "B", "C", "D", "E", "F", "G", "H", "M");
  2.  
  3.         foreach ($alpha as $letter) {
  4.             for($j=1;$j <= 26;$j++){
  5.                 print $letter.$j.", ";
  6.             }
  7.             print "<br />";
  8.         }
Sep 19 '08 #2

aas4mis
P: 97
I guess this one wasn't over my head. Here's my solution:

Expand|Select|Wrap|Line Numbers
  1.         $query = "select concat(left(row,1), mid(row,3,2)) as 'binloc' from rows where done = true group by binloc";
  2.         $results = mysql_query($query) or die("Couldn't execute query");
  3.         while ($row = mysql_fetch_row($results)){
  4.             $qyResults[] = $row[0];
  5.         }
  6.  
  7.         $alpha = array("A", "B", "C", "D", "E", "F", "G", "H", "M");
  8.         print "<table border=1>";
  9.  
  10.         for($j=1;$j <= 26;$j++){
  11.             print "<tr>";
  12.             foreach ($alpha as $letter) {
  13.  
  14.                 if ($j < 10)        //because my list is a letter 
  15.                 {                   //followed by a 2 digit number
  16.                     $quadrant = $letter."0".$j;
  17.                 }
  18.                 else
  19.                 {
  20.                     $quadrant = $letter.$j;
  21.                 }
  22.                 if (in_array($quadrant,$qyResults))
  23.                 {
  24.                     print "<td>".$quadrant."</td>";
  25.                 }
  26.                 else
  27.                 {
  28.                     print "<td bgcolor='ffff00'>X</td>";
  29.                 }
  30.                 //            print $quadrant."&nbsp;&nbsp;&nbsp;";
  31.  
  32.             }
  33.             print "</tr>";
  34.         }
  35.         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.
Sep 19 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.