I have a script that counts the amount of items in a folder, the script looks like this, which I found here:
<?php
// integer starts at 0 before counting
$i = 0;
$dir = 'folder1/images/';
if ($handle = opendir($dir)) {
while (($file = readdir($handle)) !== false){
if (!in_array($file, array('.', '..')) && !is_dir($dir.$file))
$i++;
}
}
// prints out how many were in the directory
echo "$i items";
?>
When displayed on a webpage I get the amount of items in the folder next to some text like this:
Folder 1: 12 items
The items vary, and I would like for the numbers to change color based on their value.
I don't have much knowledge regarding php. I found this script here and it seems to be what I need:
<?php
$color = "#fff";
if (($v >= 0) && ($v <= 9))
$color = "#E54028";
else if (($v >= 9) && ($v <= 15))
$color = "#F18D05";
else if ($v >= 15)
$color = "#61AE24";
echo "<span style=\"color: $color\">12</span>";
?>
I've tried changing the $v to $i, but I don't get it, and since I'm such a noob, I figured I'll ask the experts over at stackoverflow, so guys, could you help me out here? :)
Here is what my .php looks like:
<div id="body">
<?php
$color = "#000000";
if (($v >= 0) && ($v <= 9))
$color = "#E54028";
else if (($v >= 9) && ($v <= 15))
$color = "#F18D05";
else if ($v >= 15)
$color = "#61AE24";
echo "<span style=\"color: $color\">Text</span>";
?>
<ul>
<li>Folder 1:<strong>
<?php
// integer starts at 0 before counting
$i = 0;
$dir = 'folder1/images/';
if ($handle = opendir($dir)) {
while (($file = readdir($handle)) !== false){
if (!in_array($file, array('.', '..')) && !is_dir($dir.$file))
$i++;
}
}
// prints out how many were in the directory
echo "$i items";
?>
</strong></li>
</ul>
</div>