如何将数据库里面内容以不同的颜色显示在页面上?
如题。比如在数据库database1下面有张表叫table1,表有七列,每列的值都为0、1或2.如何将此张表显示在网面上,且要求当数值为0时显示红色;当数值为1时显示黄色;当数值为2时显示为绿色???
<br /> $style = array(0=>"red",1=>"yellow",2=>"gree");<br /> 根据数据库的值 输出样式<br />
<br /> $ar1=array(0,1,2);<br /> $ar2=array(0,1,2);<br /> $ar3=array(0,1,2);<br /> $ar4=array(0,1,2);<br /> $ar5=array(0,1,2);<br /> $ar6=array(0,1,2);<br /> $ar7=array(0,1,2);<br /> <br /> <br /> <table border="1" cellspacing="0" cellpadding="0" width="600"><br /> for($i=0;$i<count($ar1);$i++){<br /> echo "<tr>";<br /> echo "<td>".$ar1[$i]."</td>";<br /> echo "<td>".$ar2[$i]."</td>";<br /> echo "</tr>";<br /> }<br /> </table><br /> <br />
<br /> <style type="text/css"><br /> .r{<br /> background-color:red;<br /> }<br /> .y{<br /> background-color:yellow;<br /> }<br /> .g{<br /> background-color:green;<br /> }<br /> </style><br /> <script src="http://code.jquery.com/jquery-latest.js"></script><br /> <script type="text/javascript"><br /> $(function(){<br /> $("#abv").click(function(){<br /> $("tr td").each(function(){<br /> if($(this).text()==0){<br /> $(this).addClass("r");<br /> }else if($(this).text()==1){<br /> $(this).addClass("y");<br /> }else{<br /> $(this).addClass("g");<br /> }<br /> });<br /> });<br /> })<br /> </script><br /> <input type="button" id="abv" value="测试用按钮"/><br /> <table border="1" cellspacing="0" cellpadding="0" width="600"><br /> <tr><br /> <td/>0</td><br /> <td>2</td><br /> <td>2</td><br /> <td>1</td><br /> <td>2</td><br /> <td>2</td><br /> <td>1</td><br /> </tr><br /> <tr><br /> <td>2</td><br /> <td>2</td><br /> <td>1</td><br /> <td/>1</td><br /> <td>1</td><br /> <td>2</td><br /> <td>0</td><br /> </tr><br /> <tr><br /> <td/>0</td><br /> <td>1</td><br /> <td>2</td><br /> <td/>0</td><br /> <td>1</td><br /> <td>2</td><br /> <td>0</td><br /> </tr><br /> </table><br /> <br />
<style type="text/css"><br /> .col_0 {<br /> background-color:red;<br /> }<br /> .col_1 {<br /> background-color:yellow;<br /> }<br /> .col_2 {<br /> background-color:green;<br /> }<br /> </style>
while($row=mysql_fetch_array($result))<br /> {<br /> echo '<tr>';<br /> for($i=0; $i<7; $i++) {<br /> echo "<td class='col_{$row[$i]}'>{$row[$i]}</td>";<br /> }<br /> echo '</tr>';<br /> }