Topic: Last poll on index page

Is there any code allowing on the index page of the site to show the latest poll from the forum (sth like recent discussions in http://punbb.org/forums/viewtopic.php?id=2494 but for polls)?

Re: Last poll on index page

Now there is :) Just change the paths to your configuration and it'll hopefully work fine!

$pun_root = 'forums/';

@include $pun_root.'config.php';

// If config.php doesn't exist, PUN shouldn't be defined
if (!defined('PUN'))
    exit('config.php doesn\'t exist or is corrupt. Please run install.php to install PunBB first.');

define('PUN_DONT_UPDATE_COOKIE', 1); // This will make sure that the forum doesn't set a new cookie for the visiting user
require $pun_root.'include/common.php';

$result = $db->query('SELECT p.topic_id, p.question FROM '.$db->prefix.'polls AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id ORDER BY p.id DESC LIMIT 14') or error('Unable to fetch poll list', __FILE__, __LINE__, $db->error());

while ($cur_poll = $db->fetch_assoc($result))
{
    if ($options['censoring'] == '1')
        $cur_poll['question'] = censor_words($cur_poll['question']);
    
    if (strlen($cur_poll['question']) > 30)
        $cur_poll['question'] = trim(substr($cur_poll['question'], 0, 24)).' ...';
    
    echo "\t\t\t\t\t\t\t".'<b>·</b> <a href="'.$pun_root.'viewtopic.php?id='.$cur_poll['topic_id'].'">'.htmlspecialchars($cur_poll['question']).'</a><br>'."\n";
}

Edit: Changed to $pun_root instead of set_include_path()

3 (edited by Edward 2004-01-26 16:11)

Re: Last poll on index page

May be my question was not precise, but I was thinking of sth a little bit different.

I do not want to show on my index page, the titles of the polls, but the poll data itself. That is, when the person is visiting the index page and has not voted yet, I would like him/her to see, the poll form. And if he/she has voted I would like the results of the poll to be visible.

Is it possible?

Anyway, thanks for the above code. It will be useful for me too smile

Re: Last poll on index page

Edward wrote:

May be my question was not precise, but I was thinking of sth a little bit different.

I do not want to show on my index page, the titles of the polls, but the poll data itself. That is, when the person is visiting the index page and has not voted yet, I would like him/her to see, the poll form. And if he/she has voted I would like the results of the poll to be visible.

Is it possible?

Anyway, thanks for the above code. It will be useful for me too :)

Okey, its a bit harder yes. You mean like for all polls in the forum? It can easaly be changed so that it only show polls that the users haven't answered...

Edit: Cleaned up my spelling-mess ;)

Re: Last poll on index page

No, it is still not that sad

You can visit my site and on the index page there is a poll. I would like to replace with the latest poll of my forum (it should look and behave similarly). Is it possible?

Re: Last poll on index page

Come on, Guys! Do you really have no idea how to do it?