Another way of ignoring the last null entry would be to subtract one from the iteration count like this:
for($i = 0; $i < count($result_array) - 1; $i++)
{
...
}
Helmut's method is far more elegant on its own but what I do is combine the above with the null test that he suggested. It may seem like overkill, but better safe than sorry.