vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   database output and <select> box? (https://vborg.vbsupport.ru/showthread.php?t=267639)

Murtific 07-29-2011 05:36 PM

database output and <select> box?
 
Trying to put my database output in a <select></select> box. Any ideas how to do it in the template?

I can have the var in php in either an array or in a single variable with all the data in it.

kh99 07-29-2011 05:48 PM

With the data in an array you should be able to use the vb:each tag, like the example at the end of this article: https://vborg.vbsupport.ru/showthread.php?t=221560 (you can also search your templates for vb:each and find other examples).

Murtific 07-29-2011 06:39 PM

Code:

$chan = mysql_query("SELECT * FROM channels ORDER BY chan ASC", $connection);
        while ($list = mysql_fetch_array($chan))
        {
        $var1 = $list['chan1'];
}

$templater-register('var1', $var1);



<vb:each from="list" value="chan">
<td><select name="cGID" size="1"><option value="{vb:raw list.chan}">{vb:raw list.chan}</option></select></td>
</vb:each>

Not sure if i'm doing it right.I want it to list everything that's in that array in the drop down menu

kh99 07-29-2011 06:46 PM

I haven't actually used vb:each before, but I think you'd want this:

Code:

<td><select name="cGID" size="1">
<vb:each from="var1" value="chan">
<option value="{vb:raw chan}">{vb:raw chan}</option>
</vb:each>
</select></td>



Of course as an alternative, you could do this:

Code:

$menu = '<select name="cGID" size="1">';
$chan = mysql_query("SELECT * FROM channels ORDER BY chan ASC", $connection);
while ($list = mysql_fetch_array($chan))
        $menu .= '<option value="' . $list['chan1'] . '">' . $list['chan1'] . '</option>';
$menu .= '</select>';

$templater-register('menu', $menu);



<td>{vb:raw menu}</td>


Murtific 07-30-2011 12:46 AM

Code:

        $chan = mysql_query("SELECT * FROM channels ORDER BY chan ASC", $connection);
        while ($list = mysql_fetch_array($chan))
        {
        $chanList .= $list['gid']."<br />";
        $chanGid .= $list['chan']."<br />";
        $chanAcc .= $list['access']."<br />";
        $zlist.= "<option value='".$list['gid']."'>".$list['gid']."</option>";
        }

then..

$templater->register('zlist',$zlist);

then in the template..

<select name="derp" size="2">{vb:raw zlist}</select>



All times are GMT. The time now is 09:21 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01154 seconds
  • Memory Usage 1,723KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete