Results 1 to 4 of 4

Thread: Code compilation issues

  1. #1
    Join Date
    Feb 2012

    Unhappy Code compilation issues

    Hello scripters...

    This has probably been addressed already, but I want to be able to change elements like headers, paragraph information within one part of the site and do this using an array of images. For instance, if you were to click on image1, the div that may hold the information, name of image, image description, and price, for example, will change.

    Now, I know how to do this using a basic function technique, but I end up having to separate the code for each image, and I would like to store all the information lets say, on a database, and call the information as the user clicks. I know that there is a looping technique to do this, but I can not get it to work properly.

    I use PHP to call the information from the database, and then the javascript code eludes me to do this. I hope that this makes sense, and if nor infor is needed, please reply and I will try to answer.

  2. #2
    Join Date
    Jan 2005
    Def. need more info to understand what the problem is.

  3. #3
    Join Date
    Sep 2011
    Bristol, England, United Kingdom
    So you've got a navigation at some point on your site with images that, when clicked, will change parts of the page?

    You said you want to call the information as the user requests it from the clicks. I would not recommend that method as you will ultimately end up using more bandwidth and server power. You're better off calling all your data in one request on page load and storing it in a multi-dimensional PHP array, which can be echoed in to JavaScript arrays for client-side use.

    Because you've given no code and not much information, I can't give exact code, but it would be something along the lines of:

    PHP Code:
    // get all the data from the necessary table
    $get_data mysql_query("SELECT * FROM some_table");

    $i 0$i mysql_num_rows($get_data); $i++)
    // store the table rows in to a PHP 3-dimensional associative array.
    $results[$i] = mysql_fetch_assoc($get_data);

    Let's say you've got 3 columns in your database: name, age, gender. These are now stored in PHP as: $results[$i]['name'], $results[$i]['age'] and $results[$i]['gender'].

    You can now echo these results into JavaScript arrays for use on the client-side. You will create a JavaScript 3-dimensional array like so:

    var details= Array(name = Array(), 
                        age = Array(), 
                     gender = Array());
    Now in PHP you can echo the results in to each of these arrays like so:

    PHP Code:
    <script language="javascript">
    <?php for($i 0$i count($results); $i++)   echo "details[0][".$i."] = '" $result[$i]["name"] . "',"?>
    for($i 0$i count($results); $i++)   echo "details[1][".$i."] = '" $results[$i]["age"] . "',"?>
    for($i 0$i count($results); $i++)   echo "details[2][".$i."] = '" $results[$i]["gender"] . "',"?>
    At this point you've basically converted a 3D PHP array to a 3D JavaScript array and can now use it on the client-side.

    Because you've not given much information I can't tell you the next step. However, since you said you want to change the content of a <div> with a click of the mouse, you can use the document.getElementById() object in JavaScript to achieve this result.

    For example, a button with an onClick event which calls a function "change();". Your "change();" function would look something like:

    function change()
        document.getElementById("your_div_id").innerHTML = "something";
    You can also create a variable and give it a string value containing HTML, and set the .innerHTML value to the value of the variable.

    Please provide more information so we can help more.
    Last edited by George88; 02-23-2012 at 05:43 PM.

  4. #4
    Join Date
    Feb 2012

    Thumbs up Thank you

    I do appreciate the input. I do apologize that I didnt leave any real code... I know how it looks in my head, but I am not so advanced in javascript to even make it plain, but I do understand what you have written as an example. I think that I can build from it, and if I get stuck, I will post the issue in code then.

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.11417 seconds
  • Memory Usage 2,880KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (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
  • (2)bbcode_php
  • (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 (73):
  • 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_postinfo_query
  • fetch_postinfo
  • 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