This looks like a PHP question, not a SQL question! Anyway, move the <table> out of the loop, and then just style your <tr> tag with a border-top or border-bottom.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.