$sql = "select photopath from infochild where parentid=$id";
 $res = mysql_query($sql);
 $filenum = mysql_num_rows($res);
 $img = array();
 $j=0;
 while ($myrow=mysql_fetch_array($res)){
 $photopath=$myrow["photopath"];//图片路径
    for ($i=0;$i<$filenum;$i++){
      if (file_exists($photopath)){
     //if pic exists then give img array value
     $img[$j] = $photopath ;
 $j++;
 //at same time give hidden str value.
     $imgstr = "<img src=".$img[$j]."><br><input   type='hidden' value='".$img[$j]."' name=".$img[$j].">";
   }
}
 }      reset($img);
 while(list($key,$val)=each($img))//可以遍历数组
 {
 echo "[".$key."]->".$val."<br/>";
 }你看看有没有启发,你也可以用print_r($img);检查一下,看看吧,不明白的地方请跟贴!^_^