Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-02-2016, 05:27 PM
twistsol's Avatar
twistsol twistsol is offline
 
Join Date: Apr 2015
Location: Cottage Grove, MN
Posts: 52
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Passing array to a template to format as a table

I'm a newbie to HTML, CSS, PHP and relatively new to vBulletin, admin for less than a year, and I literally wrote my first php code yesterday. Old COBOL guys can still learn new things. :up:

Last night I created a script that gathered some data from the database and formatted it as an HTML table in the PHP script and passed that variable with text to a page and template I created by following tutorials I found here. The output on the page was fine but I'm questioning the technique.

I think it would make more sense to pass a variable as a two dimensional array to the template and have the template code display it broken out into a table to display on the page from that point.

Is this possible? If so can someone provide some hints as to what I'd need.

If it matters,
vb 4.2.3
PHP 5.4.45
Apache 2.4.16
OSX 10.11.3

Thanks much for any assistance.

Chris
Reply With Quote
  #2  
Old 03-02-2016, 05:46 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello and welcome to vBorg, Chris!

While I haven't personally used this feature, I think what you're after is like what you find in the "FORUMDISPLAY" template:

HTML Code:
<ol class="commalist">
	<vb:each from="activeusers" value="row">
		<li><a class="username" href="{vb:link member, {vb:raw row}}">{vb:raw row.musername}</a>{vb:raw row.invisiblemark}{vb:raw row.buddymark}{vb:raw row.comma}</li>
	</vb:each>
</ol>
It appears the array $activeusers is passed to the template, and then the tag:

<vb:each from="activeusers" value="row">

iterates for each row in the array, and gives the name "row" to the rows during the iterations. So, I'm thinking you would do something like:

HTML Code:
<table>
	<vb:each from="myarray" value="row">
		<tr>
			<td>{vb:raw row.column1}</td>
			<td>{vb:raw row.column2}</td>
			<td>{vb:raw row.column3}</td><td>{vb:raw row.columnn}</td>
		</tr>
	</vb:each>
</table>
Reply With Quote
Благодарность от:
twistsol
  #3  
Old 03-02-2016, 06:18 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

<a href="https://www.vbulletin.com/docs/html/main/styleref_templates_syntax" target="_blank">https://www.vbulletin.com/docs/html/...mplates_syntax</a> also contains some useful info regarding the syntax in templates.
Reply With Quote
2 благодарности(ей) от:
MarkFL, twistsol
  #4  
Old 03-02-2016, 06:28 PM
twistsol's Avatar
twistsol twistsol is offline
 
Join Date: Apr 2015
Location: Cottage Grove, MN
Posts: 52
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Mark, I think that's exactly what I was after. I'll need to look at it tonight when I'm not doing my day job.

Thanks also Dave. Clearly I need to spend more time reading about all of this stuff but time, as they say, is a commodity in short supply.

Chris

--------------- Added [DATE]1456975358[/DATE] at [TIME]1456975358[/TIME] ---------------

It worked perfectly.
Reply With Quote
Благодарность от:
MarkFL
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:08 AM.


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.03682 seconds
  • Memory Usage 2,206KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_html
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (4)post_thanks_box
  • (4)post_thanks_box_bit
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit
  • (4)post_thanks_postbit_info
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete