Yes, it would seem you only want to populate the $currentgallery array with the name.
edit: ^ I didn't word that very well. Basically you don't want to assign the found filenames in $currentgallery with an array key of $i (the current counter) because, like redhead said, you'll have an array full of holes.
When you loop through $currentgallery you may perform 5 loops, but the array keys may not necessary be 0,1,2,3,4.
So you can fix the array assignment, OR just use a
foreach loop.
eg:
PHP Code:
foreach ($currentgallery as $k => $v) {
$result1 = mysql_query("SELECT id FROM wp_piccaption WHERE picture = '$v'") or die(mysql_error());
}