Hi there,
Instead of echoing, you can assign (fetch) it into a variable and display it whenever you want to.
But the thing is, it really depends on what kind of template engine/algorithm you are using. For instance, would you like your $showrows to hold only one row at a time or all rows?
If all, then instead of echoing, you can fetch everything into $showrows with concatination operator (e.g.
$output .= "whatever_you_are_fetching"; ):
In the end you'll get $output that holds all the rows. Then simply place(echo) this var between <table> and </table> to display the table. But again, it depends on what you really need to get out of this function.
Hope this gives you some idea.