View Full Version : array/database/template
exportforce
07-30-2014, 07:54 PM
For example I have a table with UserID, Points, Timestamp,open and I want to fetch it
$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/main/styleref_templates_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 (https://vborg.vbsupport.ru/showthread.php?t=228078)
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/vbulletin-4/vbulletin-4-questions-problems-and-troubleshooting/395336-using-templates-display-custom-table-sql-query-within-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.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.