dream02008 2017-06-22 15:32
浏览 33

PHP for循环嵌套问题 - 随机破坏了一切

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大