[url]http://pastebin.com/45NyPxmt[/url] - Lua example
I want to be able to do something like this in html (lua example):
name = {}
name[1] = { "heroname", "mainattribute", "image" }
Then I want to be able to call it like the in the Lua example above but in html. And also I want to know if it is possible to call a function from another HTML file by using something like include("file.html") or something along those lines to just be able to use any global function from that file, or if there is some special way to declare global functions that can be used anywhere.
Thanks.
you don't do this in HTML, but instead look at Javascript. Have you even bothered reading what HTML, CSS, and Javascript does?
[editline]30th April 2013[/editline]
Also, you're probably asking for something like PHP.
So, you want to basically print out a multidimensional array to an HTML table.
If you stored the thing in a sane format, shouldn't be too difficult to parse it with PHP and then print it out.
Um, yeah you aren't gonna be able to do this in HTML. Look into JavaScript or PHP instead.
If you separated colums with tabs (\t) and rows with newline (\n), in PHP you could first do explode on \n in order to split the multidimensional array into rows, and then foreach the result of that, and within the foreach, explode on \t.
It's honestly not too hard, I do something really, really similar in one thing I've already done, except I don't read the contents from any specific file, the table is generated from user input.
edit: fast pseudo shit
[PHP]
<?php
//do your file open bullshit here, probably be lazy and use file_get_contents()
$content = file_get_contents(whatever.txt);
foreach(explode("\n", $content) as $key => $row){
$columns = explode("\t", $row);
//echo up some <td>'s or whatever the fuck the correct tags were
//gonna want to start the table before starting PHP though}
?>[/PHP]
The process I'd use is:
Write a lua addon to convert the table to JSON ([url]http://wiki.garrysmod.com/page/util/TableToJSON[/url]) and save it in a file.
With PHP you can use $array = file_get_contents(json_decode($url, true));
This reads the file and converts it into an assosiative array. Then using a foreach loop cycle over the array and build the HTML.
Yup, that sounds like a good idea, I'm using json_decode for something else, it works just fine as long as you're writing valid JSON, and it would save you a lot of effort.
Sorry, you need to Log In to post a reply to this thread.