page blank
#1
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>
My Projects - Support My Projects

Don't forget to rate posts!
Reply
#2
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").'";');
}
Reply
#3
It doesn't work Sad
My Projects - Support My Projects

Don't forget to rate posts!
Reply
#4
(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.
Reply
#5
Thanks destroy I had forgotten to glovalise $templates, now it works
My Projects - Support My Projects

Don't forget to rate posts!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)