html table cell validation by mysql query results

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aas4mis
    New Member
    • Jan 2008
    • 97

    #1

    html table cell validation by mysql query results

    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.
    [CODE=PHP] print "<table border=1>";
    $x=0;$y = 1;
    while ($y <= 26){
    $z = 0;
    print "<tr>";
    while ($z <= 8){
    $q = mysql_query("se lect 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>";[/CODE]
  • aas4mis
    New Member
    • Jan 2008
    • 97

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

    [CODE=php] $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 />";
    }[/CODE]

    Comment

    • aas4mis
      New Member
      • Jan 2008
      • 97

      #3
      I guess this one wasn't over my head. Here's my solution:

      [CODE=PHP] $query = "select concat(left(row ,1), mid(row,3,2)) as 'binloc' from rows where done = true group by binloc";
      $results = mysql_query($qu ery) 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($quad rant,$qyResults ))
      {
      print "<td>".$quadran t."</td>";
      }
      else
      {
      print "<td bgcolor='ffff00 '>X</td>";
      }
      // print $quadrant."&nbs p;&nbsp;&nbsp;" ;

      }
      print "</tr>";
      }
      print "</table>";[/CODE]
      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.
      Last edited by aas4mis; Sep 19 '08, 05:14 PM. Reason: Follow Up Question

      Comment

      Working...