Need help with my block code

Discussion forum for MOD Writers regarding MOD Development.
Locked
MrDave10
Registered User
Posts: 22
Joined: Mon May 17, 2010 1:05 pm

Need help with my block code

Post by MrDave10 »

Hi ive got my code layed out

Code: Select all

function display_s5_blocks($position)
{
    global $db, $auth, $user, $template;
	global $phpbb_root_path, $phpEx, $config, $script_path;
    
    $sql = 'SELECT *
        FROM ' . S5_BLOCKS . '
        WHERE block_position = "' . $position . '"
        ORDER BY left_id ASC';
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
    $allow_bbcode = $allow_urls = $allow_smilies = true;
    
    // Builds the array lists with data from the menu table
    while ($blockData = $row)
    {
        $block_content = '';
        if ($blockData['parse_bbc'] == 1)
        {
            $message_parser = new s5_parse_message($blockData['block_content']);
            $message_parser->parse($allow_bbcode, $allow_urls, $allow_smilies);
            $text_center = $message_parser->message;
            $bbcode_uid = $message_parser->bbcode_uid;
            $bbcode_bitfield = $message_parser->bbcode_bitfield;
            $bbcode_options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS;
            $block_content = generate_text_for_display($text_center, $bbcode_uid, $bbcode_bitfield, $bbcode_options);
        }
        else
        {
            $block_content = htmlspecialchars_decode($blockData['block_content'],ENT_QUOTES);
        }
        
        $s5_block = 'helloooooooo' . $block_content;
        
        return $s5_block;
    }
}


$template->assign_vars(array(
    'ADVERT4' => display_s5_blocks('s5_advert4'),
    'ADVERT5' => display_s5_blocks('s5_advert5'),
    'ADVERT6' => display_s5_blocks('s5_advert6')
));

i have in the db 2 rows with the block_position set to s5_advert4

But it will only output one
My question is how can i make it output all that contain s5_advert4

Thanks
Dave

User avatar
daroPL
Translator
Posts: 515
Joined: Tue Mar 27, 2007 11:58 am
Location: Poznan, Poland
Name: Darek
Contact:

Re: Need help with my block code

Post by daroPL »

Try this code

Code: Select all

function display_s5_blocks($position)
{
    global $db, $auth, $user, $template;
   global $phpbb_root_path, $phpEx, $config, $script_path;

    $s5_block = array();

    $sql = 'SELECT *
        FROM ' . S5_BLOCKS . '
        WHERE block_position = "' . $position . '"
        ORDER BY left_id ASC';
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
    $allow_bbcode = $allow_urls = $allow_smilies = true;
    
    // Builds the array lists with data from the menu table
    while ($blockData = $row)
    {
        $block_content = '';
        if ($blockData['parse_bbc'] == 1)
        {
            $message_parser = new s5_parse_message($blockData['block_content']);
            $message_parser->parse($allow_bbcode, $allow_urls, $allow_smilies);
            $text_center = $message_parser->message;
            $bbcode_uid = $message_parser->bbcode_uid;
            $bbcode_bitfield = $message_parser->bbcode_bitfield;
            $bbcode_options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS;
            $block_content = generate_text_for_display($text_center, $bbcode_uid, $bbcode_bitfield, $bbcode_options);
        }
        else
        {
            $block_content = htmlspecialchars_decode($blockData['block_content'],ENT_QUOTES);
        }
        
        $s5_block[] = 'helloooooooo' . $block_content;
    }

    return implode('<br />', $s5_block);
}


$template->assign_vars(array(
    'ADVERT4' => display_s5_blocks('s5_advert4'),
    'ADVERT5' => display_s5_blocks('s5_advert5'),
    'ADVERT6' => display_s5_blocks('s5_advert6')
)); 
Remember, the return statement always ends the function.

MrDave10
Registered User
Posts: 22
Joined: Mon May 17, 2010 1:05 pm

Re: Need help with my block code

Post by MrDave10 »

lol i get an error with that

if i put it like this

Code: Select all

}
    return implode('<br />', $s5_block);
}
firefox just keeps loading the page until returning this error

Fatal error: Maximum execution time of 60 seconds exceeded in D:\xampp\htdocs\gc\includes\utf\utf_tools.php on line 1828

if i put the end code like this

Code: Select all

return implode('<br />', $s5_block);
    }
}
i get error

[phpBB Debug] PHP Notice: in file /s5controls/s5_blocks/s5_blocks.php on line 61: implode() [function.implode]: Invalid arguments passed

If you have anymore ideas let me know ill be glad to try them out

and thanks for helping me

Thanks
Dave

MrDave10
Registered User
Posts: 22
Joined: Mon May 17, 2010 1:05 pm

Re: Need help with my block code

Post by MrDave10 »

and if you need any extra info let me know like link to test board or what not

Thanks
Dave

User avatar
daroPL
Translator
Posts: 515
Joined: Tue Mar 27, 2007 11:58 am
Location: Poznan, Poland
Name: Darek
Contact:

Re: Need help with my block code

Post by daroPL »

I guess it's caused by this part of the code

Code: Select all

            $message_parser = new s5_parse_message($blockData['block_content']);
            $message_parser->parse($allow_bbcode, $allow_urls, $allow_smilies);
            $text_center = $message_parser->message;
            $bbcode_uid = $message_parser->bbcode_uid;
            $bbcode_bitfield = $message_parser->bbcode_bitfield;
            $bbcode_options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS;
            $block_content = generate_text_for_display($text_center, $bbcode_uid, $bbcode_bitfield, $bbcode_options); 

Locked

Return to “[3.0.x] MOD Writers Discussion”