I can't find the issue with my code... There's two for loop for building a layout that randomly wraps together the images (from 1 to 3 photos inside a wrapper div)
Sometimes it goes well, but sometimes it gives me the error: call method to null (like the object array can't access the property).
here is the code:
if (isset($get_medias)){
//new gallery structure
$output_gallery_main.='<div id="g-fotografica" class="metro_gallery flip vertical lightbox">';
$indice=0;$loop_counter=0;
for($indice;$indice<count($get_medias);$indice++){
$rand_n=rand(0,2);
if($loop_counter==0) {
$item_size="2x2";
} else { $item_size="1x1"; }
$output_gallery_main.='<div class="tile tile_'.$item_size.' '.$loop_counter.' white">';
for($a=0;$a<=$rand_n;$a++){
$nuovo_indice=$indice+$a;
$m_media=$get_medias[$nuovo_indice];
$titolo=$m_media->get_titolo();
$alt=$m_media->get_alt();
$src=$m_media->get_src();
$thumb_src=$m_media->get_thumb();
$stato=$m_media->get_stato() == 1 ? 'visibile' : 'nascosto';
$ordine=$m_media->get_ordinamento_modello($modello);
if($stato=="visibile"){
//build the structure
$output_gallery_main.='<img src="http://'.$thumb_src.'" alt="'.$alt.'" title="'.$alt.'" data-preview="http://'.$src.'" data-caption="'.$titolo.'" />';
}
}
$output_gallery_main.='</div>';
$indice=$nuovo_indice;
$loop_counter++;
}
$output_gallery_main.='</div>';
Please help me....I'm going crazy! ps. The $get_media is an array retreived from a db, I printed out the array and it's alway well formed.