Results 1 to 4 of 4

Thread: grabbing/replacing table data from database/file

  1. #1
    Join Date
    Jul 2012

    grabbing/replacing table data from database/file

    So, I'm a newbie to databases...

    I have a table, and I want to populate it with data on a button click. However, I have no idea what type of file would be best to save the data in.

    There will be several 'sets' of information to replace the table data, and several buttons to grab and place the corresponding info. Where would I save these 'sets' of data?

    Thank you, in advance!

  2. #2
    Join Date
    Mar 2005
    Behind you...
    The first question I'll ask is, will this data be static? If it will be then you won't need an actual database or any files on the server and the data can be placed into objects.
    However, if the data will be changing then since it's tabular, a MySQL database would probably be best. But javascript cannot read or write directly to any MySQL database, thus you'll need PHP to serve as a bridge between the two. Javascript can send and receive data from a PHP script that reads/writes to your database.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  3. #3
    Join Date
    Jul 2012
    Awesome! Great information for a newbie. It will be static, but again, there will be a few tables used interchangeably, swapped by a triggered event. Would it be best then, to just include multiple tables in the html file?

    Thanks again.

  4. #4
    Join Date
    Mar 2005
    Behind you...
    Since the data is going to be static it would probably be easiest to simply load the data into javascript objects and avoid actual databases. However, a couple of things to consider would be filesize and page speed. I'm not sure how much data you have, though I think this principle should apply reguardless.

    You'll probably want to code these 'tables' of data into javascript objects. Then you'll want to include this javascript as an external script. You can have your page load this script asynchronously to avoid slowing down your page load times and prevent unnecessarily large filesizes.

    There are a lot of things that could be said and shared about javascript objects but for the sake of simplicity in your case I'll give you the most basic and relevant example I can think of:
    var $table1 = [
    	{"Column 1": "Here's some data in the first column", "Column 2": "Here's some more data", "Column 3": 1234, "Column 4": "The data could be any number of data types, such as strings, numbers or boolean values."},
    	{"Column 1": "This will be on the second row", "Column 2": "foo", "Column 3": 5678, "Column 4": "foo"},
    	{"Column 1": "This will be on the third row", "Column 2": "foo", "Column 3": 9012, "Column 4": "foo"}
    This is effectively an array of objects. Each new index in the array would be a new row in a table. Following the object format you have a key and then a value (the key being your column name and the value being the data for that cell in the table). You could duplicate this any number of times to create multiple tables that could be loaded.

    Now, as for loading this bit of code into some HTML that would be some form of a table, below is just a basic example of a function that will take the above format and turn it into a table.
    function _GenerateTable($a) {
    	var $cols = [];	
    	var $tableHTML = '<div style="display: table;">';
    	$tableHTML += '<div style="display: table-row;">';
    	for(var $b in $a[0]) $tableHTML += '<div style="display: table-cell;"><b>'+$b+'</b></div>';
    	$tableHTML += '</div>';
    	for(var $c = 0; $c < $a.length; $c++) {
    		$tableHTML += '<div style="display: table-row;">';
    		for(var $d in $a[$c]) $tableHTML += '<div style="display: table-cell;">'+$a[$c][$d]+'</div>';
    		$tableHTML += '</div>';
    	$tableHTML += '</div>';
    	return $tableHTML;
    document.getElementById("test").innerHTML = _GenerateTable($table1);
    The last line is just a simple way of generating a table with this function and placing it on the page somewhere. This code is a little sloppy, but it's mainly to show you how this can be done with objects. I wouldn't use this code for production but it can be used to get you started. Just make sure to refine the code and try to understand what it's actually doing.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.12843 seconds
  • Memory Usage 2,867KB
  • Queries Executed 13 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (4)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (71):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates