我对php和mysql的了解很少。我的网站显示特定图像的观看次数,但我希望视图以四舍五入的形式显示。这是我在网站上查看时所使用的代码
<div class="pic rounded-8" style="overflow:hidden;"><div style="margin:0 0 36px 0;overflow:hidden;border:none;height:auto;"><img src='<?php echo "./images/".$cur_image['filename'].".".$cur_image['ext'];
$viewed = $cur_image['id'];
mysql_query("UPDATE `images` SET `views` = `views`+1 WHERE `id`='$viewed'") or die("Couldnt update");
?>' style="max-width:590px;"></div></div>
<span style="font-style:italic;">Views: <?php echo $cur_image['views']; ?></span>
我尝试为$ views或$ viewed创建用于视图的函数,但是它不起作用。
有人可以指导我如何实现这一目标,并以1个小数位显示视图(例如1.2k或1.2m)
我从堆栈溢出中发现的内容(没有原始链接)修改了一个很酷的代码段。
Just replace
KB
constant with1000
. And I think this snippet does 2 decimal places. Should at least get you in the right direction.