MySQL Groups into a dropdown

Discussion forum for MOD Writers regarding MOD Development.
NLGE
Registered User
Posts: 9
Joined: Sun Mar 22, 2015 5:49 am

MySQL Groups into a dropdown

Post by NLGE »

Hi guys,

I am trying to put the groups into a drop down format. I am not having an issue grabbing the groups or anything, but with the templating system that phpbb needs to use I am having trouble displaying it properly and I am not sure how to go about displaying it correctly in a single drop down box. Here is the current code I have:

PHP:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();



$sql = 'SELECT group_name FROM phpbb_groups ORDER BY group_id';
$result = $db->sql_query($sql);
while ($groups = $db->sql_fetchrow($result))
{
    $template->assign_block_vars('somerow', array(
               'VAR1' => $groups['group_name'],
        )
    );
}

page_header('Test');

$template->set_filenames(array(
    'body' => 'test.html',
));

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
page_footer();
?>
HTML:

Code: Select all

<!-- BEGIN somerow -->
<select>
  <option>{somerow.VAR1}</option>
</select>
<!-- END somerow -->
I know it is plain, but basically what that does is create a new drop down menu for each group it pulls from the MySql table. Is there any way (I am assuming this will done in the php) to display this all in one drop down? Thanks for your help!
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53567
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: MySQL Groups into a dropdown

Post by Brf »

NLGE wrote:

Code: Select all

<!-- BEGIN somerow -->
<select>
  <option>{somerow.VAR1}</option>
</select>
<!-- END somerow -->
You only want one select box. So the select tags go outside the loop.

Code: Select all

<select>
<!-- BEGIN somerow -->
  <option>{somerow.VAR1}</option>
<!-- END somerow -->
</select>
NLGE
Registered User
Posts: 9
Joined: Sun Mar 22, 2015 5:49 am

Re: MySQL Groups into a dropdown

Post by NLGE »

Thank you very much, works perfect! Such a simple fix...

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