Web Analytics Made Easy -
StatCounter general function help - CodingForum

Announcement

Collapse
No announcement yet.

general function help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • general function help

    Hi,
    I need help creating a function. It want it to: run when the page loads and every x seconds after. On loading I need it to connect to a db(preferably w ajax) and store results as variables I can reuse in other functions. And finally, after some math equations I can do, print the results on the page.

    I've been toying with this and I've realized its not as easy as I thought. Think I'm having problems with variable scope. Php is my main scripting language, of which I am fluent and have a working version of this. But I want it to run on the client side and relieve my server.

    Sorry if this is vague or incorrectly formatted, I'm on a phone browser.

    A guide or detailed demonstrations would be great, however pointing me in the right direction would me most apreciated.

  • #2
    Unless you need to have overlapping results--that is, some of your prior results being used at the same time you are grabbing new results--just make *all* your variables page scope and you should be fine. That is, do *not* use var name inside of your functions. Declare the relevant variables outside the functions (or not at all) and they will be page scope.

    But your question is so vague it's hard to guess more than that.
    Be yourself. No one else is as qualified.

    Comment


    • #3
      I thought of that. Apparently I'm not calling them correctly.

      Two specific problems I'm having are calling the variables in the main page and assigning them values from a database.

      If a=1 inside my external js, what do I need to do to get that value to the index page. I've tried document.write(a) but I get a undefined. I though "a" would be global since my external js variable has no "var" when assigning.

      When do a php echo in the head I have no problems assigning values to variables, but when I try it in ext the values aren't set. What's the proper code for this?

      Comment


      • #4
        Sorry, you've lost me.

        You need to show some code example(s), I think.

        When you say "external js page" do you just mean one you included in the main page via
        Code:
        <script type="text/javascript" src="external.js"></script>
        ?? If so, then any variables defined in that file should be available in the main page at any point *after* the </script> tag for the external file.
        Be yourself. No one else is as qualified.

        Comment


        • #5
          Maybe I just go it.

          Are you saying you are doing
          Code:
          <script type="text/javascript" src="external.js"></script>
          And then expecting to be able to do something like
          Code:
          var a = "<?php echo something; ?>";
          inside of the "external.js" file????

          Nope. No way. Never.

          If you want PHP in the external file, then the external file must *ITSELF* be a PHP file:
          Code:
          <script type="text/javascript" src="external.[B][COLOR="Red"]php[/COLOR][/B]"></script>
          Now, that file could then actually consist of 98% JavaScript with just the needed PHP, but if, for example, the main page is using a database to pull data from, then the external.php file would also have to do so.
          Be yourself. No one else is as qualified.

          Comment

          Working...
          X
          😀
          🥰
          🤢
          😎
          😡
          👍
          👎