所以输出工作完美,但是我需要帮助的是SQL输出数据时,我希望数据基于状态是某种颜色。该查询将拉出所有不是“ PROD”,“ NM”,“ TERM”,“ NULL”,“ IDLE”,“ YER”的状态。它将在表中显示的状态为“ DOWN”,“ PM”和“ MDS”。我想要输出的颜色是蓝色,黄色,红色。有人可以帮我吗?先感谢您!
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST GET);
use CGI qw/:standard /;
use DBI;
$dbh = DBI->connect('DBI:ODBC:SMSDWDE2','admin','admin',{RaiseError =>1, AutoCommit=>1});
my $q = new CGI();
print $q->header;
print $q->start_html(-head=>meta({-http_equiv => 'X-UA-Compatible',
-content=>'IE=edge,chrome=1'}),
-style => {'src'=>'css/eq - Copy1.css'},
{'src'=>'vendor/perfect-scrollbar/perfect-scrollbar.css'},
{'src'=>'vendor/bootstrap/css/bootstrap.min.css'},
{'src'=>'fonts/font-awesome-4.7.0/css/font-awesome.min.css'},
{'src'=>'vendor/animate/animate.css'},
{'src'=>'vendor/select2/select2.min.css'},
{'src'=>'css/util.css'},
{'src'=>'css/main.css'},
-script =>{'type'=>'text/javascript','src'=>'js/main.js'},
{'type'=>'text/javascript','src'=>'vendor/jquery/jquery-3.2.1.min.js'},
{'type'=>'text/javascript','src'=>'vendor/bootstrap/js/popper.js'},
{'type'=>'text/javascript','src'=>'vendor/bootstrap/js/bootstrap.min.js'},
{'type'=>'text/javascript','src'=>'vendor/select2/select2.min.js'},
{'type'=>'text/javascript','src'=>'vendor/perfect-scrollbar/perfect-scrollbar.min.js'},
-title=>'MET IN PHOTO');
print "
<div id='wrapper'>
<nav class='navbar navbar-inverse navbar-fixed-top' role='navigation'>
<div class='navbar-header'>
<button type='button' class='navbar-toggle' data-toggle='collapse' data-target=''.navbar-ex1-collapse'>
<span class='sr-only'>Toggle navigation</span>
<span class='icon-bar'></span>
<span class='icon-bar'></span>
<span class='icon-bar'></span>
</button>
<a class='logo' href='#'>
<img src='images/ti-logo.png' alt='CoolAdmin' />
</a>
</div>
<div class='collapse navbar-collapse navbar-ex1-collapse'>
<ul id='active' class='nav navbar-nav side-nav'>
<li><a href='CriticalToolsMet.html'><i class='fa fa-globe'></i> METROLOGY</a></li>
<li><a href='CriticalToolsCMPIMP.html'><i class='fa fa-globe'></i> CMP/IMP</a></li>
<li><a href='CriticalToolsDIFFWET.html'><i class='fa fa-globe'></i> DIFF/WET</a></li>
<li><a href='CriticalToolsPHOTO.html'><i class='fa fa-globe'></i> PHOTO</a></li>
<li><a href='CriticalToolsPLASMA.html'><i class='fa fa-globe'></i> PLASMA</a></li>
<li><a href='CriticalToolsTHINFILM.html'><i class='fa fa-globe'></i> THINFILM</a></li>
</ul>
<ul class='nav navbar-nav navbar-right navbar-user'>
<li class='divider-vertical'></li>
<li>
<form class='navbar-search'>
<input type='text' placeholder='Search' class='form-control'>
</form>
</li>
</ul>
</div>
</nav>
<div id='page-wrapper'>
<div class='row'>
<div class='col-lg-12'>
<h1>Critical Dashboard <small>Metrology</small></h1>
</div>
</div>
<div class='row'>
<div class='col-lg-12'>
<div class='panel panel-primary'>
<div class='panel-heading'>
<h3 class='panel-title'><i class='fa fa-bar-chart-o'></i> Fab Dashboard - DMOS5 </h3>
</div>
<table class='table'>
<thead>
<tr>
<th>MISTI</th>
<th>STATE</th>
<th>HRS</th>
</tr>
</thead>
</div>";
$sqlstr="Select
g.entity as MISTI,
t.cur_state as STATE,
ROUND(((SYSDATE-t.cur_state_dttm)*24),2) AS HRS
From Entity_Grp_Lst g
left outer join trk_id_def t
on g.facility = t.facility
and g.grp_type = t.grp_type
and g.entity=t.entity
and g.grp_type = '720'
WHERE t.cur_state NOT IN ('PROD','NM','TERM','NULL','IDLE', 'YER')
and Entity_Grp_type = '041'
and g.ENTITY_GRP in ('MET')
-- add and g.entity in ('WSI04') to list all tools
AND ROUND(((SYSDATE-t.cur_state_dttm)*24),2) > 48
order by t.cur_state_DTTM desc
";
$sth = $dbh->prepare($sqlstr);
$sth->execute();
$sth->bind_columns(undef, \$MISTI, \$STATE, \$HRS);
while($sth->fetch()) {
print "
<tbody>
<tr class='row100 body'>
<td class='cell100 column1'><FORM ACTION='http://d5lxgenwebapp01z.dal.make.ti.com/get_de1_de2_misti_comments.pl' METHOD='POST' target='_blank' NAME='userInput2'>
<INPUT TYPE='hidden' NAME='eq' MAXLENGTH='8' VALUE='$MISTI'>
<INPUT TYPE='hidden' NAME='pages' SIZE='3' MAXLENGTH='2' VALUE='50'>
<INPUT TYPE='submit' NAME='submit' VALUE='$MISTI'></form></td>
<td class='cell100 column2'>$STATE</td>
<td class='cell100 column3'>$HRS</td>
</tr>
</tr>";
}
print "</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>";
$sth->finish();
$dbh->disconnect();
print "
</body></html>";
答案 0 :(得分:3)
您可以对该代码进行一些改进。
use strict
和use warnings
。并解决它们揭示的问题(主要是通过my
的外观声明变量)。use CGI /:standard/
可以将CGI函数的负载导入您的名称空间,但是您只能将这些函数作为方法(在$q
中)作为CGI对象上的方法来调用,因此不需要导入。new CGI
)创建CGI对象。这将在99%的时间内起作用,但是在极少数情况下,如果它中断了,您将浪费大量时间来查找问题。最好改用CGI->new
。start_html()
)中的HTML创建功能已deprecated for some time now。请不要使用它们。答案 1 :(得分:2)
只需将值重新用作类名
<td class='cell100 column2 $STATE'>$STATE</td>
我也修复了一些非法的HTML元素
.DOWN {
color: blue
}
.PM {
color: yellow
}
.MDS {
color: red
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<div id='page-wrapper'>
<div class='row'>
<div class='col-lg-12'>
<h1>Critical Dashboard <small>Metrology</small></h1>
</div>
</div>
<div class='row'>
<div class='col-lg-12'>
<div class='panel panel-primary'>
<div class='panel-heading'>
<h3 class='panel-title'><i class='fa fa-bar-chart-o'></i> Fab Dashboard - DMOS5 </h3>
</div>
<table class='table'>
<thead>
<tr>
<th>MISTI</th>
<th>STATE</th>
<th>HRS</th>
</tr>
</thead>
<tbody>
<tr class='row100 body'>
<td class='cell100 column1'>
<form ACTION='http://d5lxgenwebapp01z.dal.make.ti.com/get_de1_de2_misti_comments.pl' METHOD='POST' target='_blank' NAME='userInput2'>
<INPUT TYPE='hidden' NAME='eq' MAXLENGTH='8' VALUE='$MISTI' />
<INPUT TYPE='hidden' NAME='pages' SIZE='3' MAXLENGTH='2' VALUE='50' />
<INPUT TYPE='submit' NAME='submit' VALUE='$MISTI' />
</form>
</td>
<td class='cell100 column2 DOWN'>DOWN</td>
<td class='cell100 column3'>$HRS</td>
</tr>
<tr class='row100 body'>
<td class='cell100 column1'>
<form ACTION='http://d5lxgenwebapp01z.dal.make.ti.com/get_de1_de2_misti_comments.pl' METHOD='POST' target='_blank' NAME='userInput2'>
<INPUT TYPE='hidden' NAME='eq' MAXLENGTH='8' VALUE='$MISTI' />
<INPUT TYPE='hidden' NAME='pages' SIZE='3' MAXLENGTH='2' VALUE='50' />
<INPUT TYPE='submit' NAME='submit' VALUE='$MISTI' />
</form>
</td>
<td class='cell100 column2 PM'>PM</td>
<td class='cell100 column3'>$HRS</td>
</tr>
<tr class='row100 body'>
<td class='cell100 column1'>
<form ACTION='http://d5lxgenwebapp01z.dal.make.ti.com/get_de1_de2_misti_comments.pl' METHOD='POST' target='_blank' NAME='userInput2'>
<INPUT TYPE='hidden' NAME='eq' MAXLENGTH='8' VALUE='$MISTI' />
<INPUT TYPE='hidden' NAME='pages' SIZE='3' MAXLENGTH='2' VALUE='50' />
<INPUT TYPE='submit' NAME='submit' VALUE='$MISTI' />
</form>
</td>
<td class='cell100 column2 MDS'>MDS</td>
<td class='cell100 column3'>$HRS</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>