vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   array/database/template (https://vborg.vbsupport.ru/showthread.php?t=313354)

exportforce 07-30-2014 07:54 PM

array/database/template
 
For example I have a table with UserID, Points, Timestamp,open and I want to fetch it
PHP Code:

$ergebnis=$db->query_read('SELECT * FROM ' TABLE_PREFIX 'lotto WHERE open="1" ORDER BY gameid DESC'); 

(Open is just for me to know if this row is still being used. If it is 1 it will be needed)

So if I fetch it via mysql_fetch_object how do I use that so I can create a list ? Normally I would just use a while and echo, but here I have to register the variables to the template...
So how would I use this?

thanks

Scanu 07-30-2014 11:03 PM

It depends, how are you printing the template? There many ways to do it: you can register variables and print the template in the cycle and you will get printed the template with different values per each row. Or you can register an array to the template and then use the vb:each function in that template. See documentation about vb:each:https://www.vbulletin.com/docs/html/...mplates_syntax

exportforce 07-31-2014 05:23 AM

Do I need something extra to register a variable as array ?
Or just use mysql_fetch_array, register it with the templater and go ?

Scanu 07-31-2014 01:04 PM

You can register it as you would register a variable, if you have any problems just let me now and please provide some codes so it's easier to help you :)

Lynne 07-31-2014 04:22 PM

Cellarius wrote a really good article that you may be interested in - [vB4] Rendering templates and registering variables - a short guide

exportforce 07-31-2014 04:24 PM

Found the problem :)
Was a very stupid typo on my side.

Didn't think all that would be working that easy... if I really get this game running I'll mostly going to check how to make it into a real addon.

edit: @Lynne thats quite handy too, but I did it this way which is far more userfriendly, at least for my coding type: http://www.vbulletin.com/forum/forum...hin-while-loop

And I did it with mysql_fetch_object as I find it way easier to understand than the array way, which was just as last resort. :)

Edit 2: How do I round numbers in the template?

edit 3: Found out. nice you can stack those {vb:XX YY} stuff into oblivion...

Lynne 07-31-2014 04:41 PM

Glad you got it working.


All times are GMT. The time now is 10:47 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.00980 seconds
  • Memory Usage 1,725KB
  • 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
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)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