No Problem!
Always difficult to find mistakes in your code, as you get "code blindness" lol, you see what you think it should be doing, rather than what it is actually doing.
It helps to print out the contents of variables in situations like this, so you can see whats going on at each step. If i`m creating complex code pages, then I add in debugging statements as I write the code, all triggered by a master variable at the top of the page. A much simplified example would be:
PHP Code:
$debug = 0
if($debug == 1){
echo "$i = " . $i;
}
If the code doesn't do what you expect, just set $debug to 1, so it prints out all the variables at every step. Also makes it much easier if something breaks in the future (if your taking data from an external source), as you can just turn on debug and it helps to fix the problem much faster.
If you're happy that the page is working fine and won't change you can remove the debugging statements.