Heim > Fragen und Antworten > Hauptteil
Ich habe jetzt eine Tabelle wie diese, die aus der Datenbank gelesen wird. Das Folgende ist der PHP-Code. Der Effekt, den ich jetzt benötige, besteht darin, die Farben entsprechend zu unterteilen Tierkreiszeichen (zum Beispiel: 01, 13, 25, 37 und 49 gehören zu Hahn, schreiben Sie einfach „Hahn“ unter das Alter mit rotem Hintergrund. 02, 14, 26 und 38 gehören zu „Affe“, schreiben Sie einfach „Affe“ unter das Alter , mit blauem Hintergrund...), hier ist das Rendering, das ich mit PS gemacht habe. Kann mir jemand helfen? Ich hoffe, Gott kann mir einen Rat geben
辕天2017-07-24 23:07:34
<?php /* * Created on 2017-7-24 * 十二生肖显示 * To change the template for this generated file go to * Window - Preferences - PHPeclipse - PHP - Code Templates */ error_reporting(0); function num($no){ $num = $no % 12; //取模判断生肖,0-11数字对应具体的生肖。测试以1为鼠开始,12对应猪。 switch ($num) { case 1: echo "<div style='background-color:#CC3366'>".$no."<br>鼠</div>"; break; case 2: echo "<div style='background-color:#FF0000'>".$no."<br>牛</div>"; break; case 3: echo "<div style='background-color:#00FF00'>".$no."<br>虎</div>"; break; case 4: echo "<div style='background-color:#0000FF'>".$no."<br>兔</div>"; break; case 5: echo "<div style='background-color:#FFFF00'>".$no."<br>龙</div>"; break; case 6: echo "<div style='background-color:#00FFFF'>".$no."<br>蛇</div>"; break; case 7: echo "<div style='background-color:#FF00FF'>".$no."<br>马</div>"; break; case 8: echo "<div style='background-color:#C0C0C0'>".$no."<br>羊</div>"; break; case 9: echo "<div style='background-color:#7FFFD4'>".$no."<br>猴</div>"; break; case 10: echo "<div style='background-color:#8A2BE2'>".$no."<br>鸡</div>"; break; case 11: echo "<div style='background-color:#A52A2A'>".$no."<br>狗</div>"; break; case 0: echo "<div style='background-color:#FAEBD7'>".$no."<br>猪</div>"; break; default: echo "<div style='background-color:#F0F8FF'>".$no."读取数据出错!</div>"; break; } } ?> <table border=1; width="600px;"> <tr><th>Number</th><th>No.1</th><th>No.2</th><th>No.3</th><th>No.4</th><th>No.5</th><th>No.5</th><th>No.7</th><th>操 作</th></tr> <tr style="text-align:center"> <td>Num1</td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><a href="#">修改</a> <a href="#">删除</a></td> </tr> <tr style="text-align:center"> <td>Num2</td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><a href="#">修改</a> <a href="#">删除</a></td> </tr> <tr style="text-align:center"> <td>Num3</td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><a href="#">修改</a> <a href="#">删除</a></td> </tr> <tr style="text-align:center"> <td>Num4</td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><a href="#">修改</a> <a href="#">删除</a></td> </tr> <tr style="text-align:center"> <td>Num5</td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><a href="#">修改</a> <a href="#">删除</a></td> </tr> <tr style="text-align:center"> <td>Num6</td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><a href="#">修改</a> <a href="#">删除</a></td> </tr> <tr style="text-align:center"> <td>Num7</td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><?php num(rand(1,49));?></td> <td><a href="#">修改</a> <a href="#">删除</a></td> </tr> </table>
辕天2017-07-24 22:54:26
设置十二种颜色,并让每种颜色对应一个1-12中的数字(及生肖)。测试的数据随机生成1-49,可能有重复。
一个方法 num($no); $no为取得数据。
为方便测试,数据全部为随机生成1-49的数。