Ah... I think I might know why....
Your check (although dependent upon register_globals being on) does not account for $num being empty. So a url like:
display.php?num=
Will have the next image being 1, and the previous as -1. Here's a slight fix:
<?php
if(isset($_GET['num']))
$num = $_GET['num'];
else
$num = 1;
if(empty($num))
$num = 1;
Now, you could take all of those lines, and put them into 1 line:
<?php
$num = (isset($_GET['num']) && !empty($_GET['num']) ? $_GET['num'] : 1);
Notice how I used the $_GET super-global instead of just assuming that $num will be populated? That's because as of php 5 vanilla installations, register_globals is off. As of php 6, it won't even be available (it's a security concern).
I should also point out that when $num = 0, the same issues happen. So it's best to check if $num > 1.... in the one-liner it would be:
$num = (isset($_GET['num']) && !empty($_GET['num']) && $_GET['num'] > 0) ? $_GET['num'] : 1);