Попогите с циклом

Все блоги / DLE движок для сайтов 23 апреля 2014 389   
Попогите с циклом
Добрый вечер уважаемые! Имеется такая проблема. Написал цикл для вывода всех персонажей с бд. С приоритетом priority_id 1 в один блок а с priority_id 2 во второй блок. Все выводится, но не так как нужно. Выводит так: основной персонаж | второстепенный персонаж в блоке 1 основной персонаж | второстепенный персонаж в блоке 2 а нужно основной персонаж | основной персонаж в блоке 1 второстепенный персонаж | второстепенный персонаж в блоке 2 Прилагаю скриншоты: как выводит http://take.ms/wqQ9W как нужно http://take.ms/TXufy Прилагаю код

 characters.news.php

dir = TEMPLATE_DIR;     $tpl2->load_template('characters.news.tpl');     // Выполняем нужный нам запрос в БД.     $res = $db->query("SELECT priority_id, main_name, russian_name, foto FROM " . PREFIX . "_characters ORDER BY priority_id ");     $_perses = array();     $_persesCount = 0;     while ($row = $db->get_row($res)) {     $_perses[$row['priority_id']][] = $row;     $_persesCount++;     }     foreach ($_perses[1] as $i => $row) {     if (!isset($_perses[2][$i]))         continue;     $tpl2->set('{main_name_main}', $row['main_name']);     $tpl2->set('{russian_name_main}', $row['russian_name']);     if ($row['foto'] and ( file_exists(ROOT_DIR . "/uploads/characters/foto/mini/" . $row['foto']))) {         $tpl2->set('{foto_main}', "");     } else {         $tpl2->set('{foto_main}', "");     }     $row = $_perses[2][$i];     $tpl2->set('{main_name_secondary}', $row['main_name']);     $tpl2->set('{russian_name_secondary}', $row['russian_name']);     // Выводим фото для основных персонажей.     if ($row['foto'] and ( file_exists(ROOT_DIR . "/uploads/characters/foto/mini/" . $row['foto']))) {         $tpl2->set('{foto_secondary}', "");     } else {         $tpl2->set('{foto_secondary}', "");     }     $tpl2->compile('content');     }     //Компилируем     //  $tpl2->compile('content');     $character_buffer = $tpl2->result['content'];     unset($tpl2); }



 characters.news.tpl



    

    

        {foto_main}     

    

    

{main_name_main}

    

{russian_name_main}

    

    





    

    

        {foto_secondary}     

    

    

{main_name_secondary}

    

{russian_name_secondary}

    

    





Буду благодарен за помощь.
  • Оцените публикацию
  • 0

Похожие публикации

@
  • bowtiesmilelaughingblushsmileyrelaxedsmirk
    heart_eyeskissing_heartkissing_closed_eyesflushedrelievedsatisfiedgrin
    winkstuck_out_tongue_winking_eyestuck_out_tongue_closed_eyesgrinningkissingstuck_out_tonguesleeping
    worriedfrowninganguishedopen_mouthgrimacingconfusedhushed
    expressionlessunamusedsweat_smilesweatdisappointed_relievedwearypensive
    disappointedconfoundedfearfulcold_sweatperseverecrysob
    joyastonishedscreamtired_faceangryragetriumph
    sleepyyummasksunglassesdizzy_faceimpsmiling_imp
    neutral_faceno_mouthinnocent

Архив публикаций