Help to resolve Syntax error, unexpected ‘endwhile’ (T_ENDWHILE) [closed]

Check your short_open_tag setting in php.ini. You have a mixture in this code. If the setting is switched off, it may be that the statements using short tags are not being parsed.

This, in particular, maybe causing the loops to be “out of sync”

                        <?
                }
                ?>

If short_open_tags is off, the foreach loop will not be looped and encounter an endwhile prematurely.