The following is a complete test script adapted from a class that I'm developing. The object of the script is to update x and y coordinates for absolutely positioning an image, in this case onto a calender. I've been through this code again and again and again and cannot figure out why the 'for' statements do not fire. Nothing between the for statements executes or outputs. The $y coordinate updates as it should but the value of $x does not change. There has to be something wrong with my for loop logic. But I can't see what it is.
Maybe a new set of eyes will help!
Thanks in advance!
: )
Rich
Code:
<?php
function build_icons()
{
$icon[29] = 'star.png';
$icon[34] = 'star.png';
$offset_left = (int) 65;
$offset_top = (int) 50;
if (isset($icon) && is_array($icon))
{
foreach($icon as $i => $file)
{
# Return x and y to default values
$x = (int) 35;
$y = (int) 125;
# Range 0-6 is the first row of the calender
if ($i >= 0 && $i <= 6)
{
for($d = 0, $f = 0; $f == $i; $d++, $f++)
{
if ($d > 0) $x = ($x + ($offset_left * $d));
}
}
else if ($i >= 7 && $i <= 13)
{
$y = ($y + $offset_top);
for($d = 0, $f = 7; $f == $i; $d++, $f++)
{
if ($d > 0) $x = ($x + ($offset_left * $d));
}
}
else if ($i >= 14 && $i <= 20)
{
$y = ($y + ($offset_top * 2));
for($d = 0, $f = 14; $f == $i; $d++, $f++)
{
if ($d > 0) $x = ($x + ($offset_left * $d));
}
}
else if ($i >= 21 && $i <= 27)
{
$y = ($y + ($offset_top * 3));
for($d = 0, $f = 21; $f == $i; $d++, $f++)
{
if ($d > 0) $x = ($x + ($offset_left * $d));
}
}
else if ($i >= 28 && $i <= 34)
{
$y = ($y + ($offset_top * 4));
for($d = 0, $f = 28; $f == $i; $d++, $f++)
{
if ($d > 0) $x = ($x + ($offset_left * $d));
}
}
else if ($i >= 35 && $i <= 41)
{
$y = ($y + ($offset_top * 5));
for($d = 0, $f = 35; $f == $i; $d++, $f++)
{
if ($d > 0) $x = ($x + ($offset_left * $d));
}
}
echo "<img src='images/calender/icons/{$file}' style='position: absolute; top: {$y}px; left: {$x}px; z-index: 99; width: 25px; height: 25px;' />";
}
} else {
echo "Error: icon is not an array or is not set";
}
}
build_icons();
?>
:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::