Please take a look and teach me this newbie.
大浪淘金
大浪淘金 2017-07-22 15:08:00
0
4
1162

QQ截图20170722144814.png

I now have a table like this. The numbers in it are ages, which are read from the database. The following is the php code

QQ截图20170722145017.png

The effect I require now is to divide the colors according to the zodiac (for example: 01, 13, 25, 37, 49 is a chicken, just write chicken below the age, the background color is red. 02, 14, 26, 38 If you are a monkey, just write monkey below the age, the background color is blue, and so on...), the following is the rendering I made with PS

QQ截图20170722150337.png

Is there any master who can help me? I just learned PHP and I still don’t understand the basics of PHP. I hope the master can give me some advice. Thank you very much.


大浪淘金
大浪淘金

reply all(4)
立伟

Write 12 styles, such as hou ji or 1 2, etc. Set 12 zodiac signs, such as hou ji or 1 2, etc. Just set the style directly when looping

辕天
<?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>&nbsp;&nbsp;<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>&nbsp;&nbsp;<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>&nbsp;&nbsp;<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>&nbsp;&nbsp;<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>&nbsp;&nbsp;<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>&nbsp;&nbsp;<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>&nbsp;&nbsp;<a href="#">删除</a></td>
	</tr>
</table>


辕天

Set twelve colors, and let each color correspond to a number (and zodiac sign) from 1-12. The test data is randomly generated from 1 to 49, and there may be duplicates. 20170701.png
A method num($no); $no is to obtain data.
20170702.png

For the convenience of testing, all data are randomly generated numbers from 1 to 49.

20170703.png

  • reply The idea is roughly like this. If it is specific, it can be further optimized. It is best that the zodiac sign corresponding to the parameters in the method can be customized.
    辕天 author 2017-07-24 23:06:08
ringa_lee

You have to find the pattern. The difference between each number is 12. The chicken sign starts from 1 and adds 12, while the monkey sign starts from 2 and adds 12.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!