ok, first - no matter how many <? ?> you have on your page, you only need to connect once. Ideally in the original <?php .... ?> pair, but it persists on the page as a whole, regardless of embedded HTML.
line 68, 69, 71 - You are doing the same operation twice, and in fact you are ignoring data.$num = mysql_num_rows($query); // this is meant to check the number of rows returned. That's it!
so if by calling that, and then checking if(!$result) {} you essentially just asked if anything was there, assign that number to $num. If something is there, then do something. And then you forget about $num.
it is usually used as:
$result = mysql_query($query);
$num = mysql_num_rows($result);
if ($num > 0) { //run my script } else { //oops! No data! }
Now, as for the rest of what you have going on.. I think you need to be a little more clear.
Are you having trouble with your data displaying properly? Or is it not updating properly with the 2nd page?