在我的数据库中有数字1
, 2
, 2.5
, 3
, 3.5
, 4
, 4.5
和5
我想将这些数字转换为星号。
我有一颗全星和半颗星。
从数据库获取信息后我该如何做到这一点?
我在数据库中有评级标签。
最佳答案
<?php
for($x=1;$x<=$starNumber;$x++) {
echo '<img src="path/to/star.png" />';
}
if (strpos($starNumber,'.')) {
echo '<img src="path/to/half/star.png" />';
$x++;
}
while ($x<=5) {
echo '<img src="path/to/blank/star.png" />';
$x++;
}
?>
*假设您使用的是 PHP
关于php - 将数字转换为视觉评级(星星)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10250825/