MyBB Community Forums
page blank - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Development (https://community.mybb.com/forum-68.html)
+---- Thread: page blank (/thread-174011.html)



page blank - chack1172 - 2015-08-05

Hello, I've finished a plugin but there's a bug. I know where code is wrong but I can't fix it:

function news_show(){
    global $db, $news, $news_list, $news_content;
    $l_news = $db->write_query("SELECT * FROM ".TABLE_PREFIX."news ORDER BY id DESC");
    if($db->num_rows($l_news) > 0){
        $news_content = "Non ci sono news da mostrare";
    } else {
        while($row = $db->fetch_array($l_news)){
            $news_content .= $row['text'];
        }    
    }
    
    eval('$news_list = "'.$templates->get("news_list").'";');
    eval('$news = "'.$templates->get("news").'";');
}

Templates

news
<div class="news">
    <div class="msg">
        <ul>
            {$news_list}
        </ul>
    </div>
</div>

news_list
<li class="quotes">{$news_content}</li>



RE: page blank - Destroy666 - 2015-08-05

Your code doesn't make much sense. This would be more logical (I also optimised it a bit and used simple_select for the simple query):
function news_show()
{
    global $db, $news;

    $l_news = $db->simple_select('news', 'text', '', array('order_by' => 'id', 'order_dir' => 'DESC'));
    $newslist = '';

    while($row = $db->fetch_array($l_news))
    {
         $news_content = htmlspecialchars_uni($row['text']);
         eval('$news_list .= "'.$templates->get("news_list").'";');
    }

    if(!$news_list)
    {
         $news_content = "Non ci sono news da mostrare";
         eval('$news_list = "'.$templates->get("news_list").'";');
    }

    eval('$news = "'.$templates->get("news").'";');
}



RE: page blank - chack1172 - 2015-08-05

It doesn't work Sad


RE: page blank - Destroy666 - 2015-08-05

(2015-08-05, 08:00 PM)chack1172 Wrote: It doesn't work Sad

That doesn't really help us with further checking. What exactly doesn't work? The code above should work if the templates are exact copies of those posted above. However, you also need to globalise $templates as I just noticed.


RE: page blank - chack1172 - 2015-08-06

Thanks destroy I had forgotten to glovalise $templates, now it works