Julian,
what do you mean by "whilst looping"? Do you want each individual message to appear in its own pop-up window? If so, try the following:
<?
for ($g=0;$g<$num_messages;$g++){
?><script language="javascript">
myWindow=window.open("myscript.php?messageid=<?echo $mess_id?>";
</script>
<?}
?>
And have the popup pull the message out of the db.
Good luck.
B.