Skip to content Skip to sidebar Skip to footer

Formatting Data To Be A Certain Color

So the output works perfect but what I need help on is when the SQL outputs the data and I would like the data to be a certain color based on states. This query will pull all the s

Solution 1:

There are a few improvements that you can make to this code.

  • Always have use strict and use warnings in your code. And fix the problems they reveal (mostly declaring variables with my by the looks of it).
  • You have use CGI /:standard/ which imports a load of CGI's functions into your namespace, but then you only call those functions as methods on your CGI object (in $q) so that import is unnecessary.
  • You use indirect object notation (new CGI) to create your CGI object. This will work 99% of the time but in the rare cases when it breaks you will waste days tracking down the problem. Far better to use CGI->new instead.
  • The HTML creation functions in CGI.pm (you use start_html()) have been deprecated for some time now. Please don't use them.
  • Having raw HTML in your Perl code is likely to be a maintenance problem (as you seem to have discovered, given the errors in your HTML). I strongly recommend moving your HTML out of your Perl code and into templates. CGI::Alternatives has some suggestions on ways to do this.

Solution 2:

Just reuse the values as class names

<td class='cell100 column2 $STATE'>$STATE</td>

I have fixed a few illegal HTML elements too

.DOWN {
  color: blue
}

.PM {
  color: yellow
}

.MDS {
  color: red
}
<linkrel="stylesheet"href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" /><divid='page-wrapper'><divclass='row'><divclass='col-lg-12'><h1>Critical Dashboard <small>Metrology</small></h1></div></div><divclass='row'><divclass='col-lg-12'><divclass='panel panel-primary'><divclass='panel-heading'><h3class='panel-title'><iclass='fa fa-bar-chart-o'></i> Fab Dashboard - DMOS5 </h3></div><tableclass='table'><thead><tr><th>MISTI</th><th>STATE</th><th>HRS</th></tr></thead><tbody><trclass='row100 body'><tdclass='cell100 column1'><formACTION='http://d5lxgenwebapp01z.dal.make.ti.com/get_de1_de2_misti_comments.pl'METHOD='POST'target='_blank'NAME='userInput2'><INPUTTYPE='hidden'NAME='eq'MAXLENGTH='8'VALUE='$MISTI' /><INPUTTYPE='hidden'NAME='pages'SIZE='3'MAXLENGTH='2'VALUE='50' /><INPUTTYPE='submit'NAME='submit'VALUE='$MISTI' /></form></td><tdclass='cell100 column2 DOWN'>DOWN</td><tdclass='cell100 column3'>$HRS</td></tr><trclass='row100 body'><tdclass='cell100 column1'><formACTION='http://d5lxgenwebapp01z.dal.make.ti.com/get_de1_de2_misti_comments.pl'METHOD='POST'target='_blank'NAME='userInput2'><INPUTTYPE='hidden'NAME='eq'MAXLENGTH='8'VALUE='$MISTI' /><INPUTTYPE='hidden'NAME='pages'SIZE='3'MAXLENGTH='2'VALUE='50' /><INPUTTYPE='submit'NAME='submit'VALUE='$MISTI' /></form></td><tdclass='cell100 column2 PM'>PM</td><tdclass='cell100 column3'>$HRS</td></tr><trclass='row100 body'><tdclass='cell100 column1'><formACTION='http://d5lxgenwebapp01z.dal.make.ti.com/get_de1_de2_misti_comments.pl'METHOD='POST'target='_blank'NAME='userInput2'><INPUTTYPE='hidden'NAME='eq'MAXLENGTH='8'VALUE='$MISTI' /><INPUTTYPE='hidden'NAME='pages'SIZE='3'MAXLENGTH='2'VALUE='50' /><INPUTTYPE='submit'NAME='submit'VALUE='$MISTI' /></form></td><tdclass='cell100 column2 MDS'>MDS</td><tdclass='cell100 column3'>$HRS</td></tr></tbody></table></div></div></div></div>

Post a Comment for "Formatting Data To Be A Certain Color"