Results 1 to 6 of 6

Thread: Calling a function in a class from an html doc

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Godzone, oops Oz
    Posts
    355

    Question Calling a function in a class from an html doc

    Is this possible? Don't see why it shouldn't be but thought I would ask before hitting the class bandwagon and stuffing up our development effort

    <form action="process.php?mod=2" method="post">

    Using a switch function in process.php to call the correct function.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Calling a function in a class from an html doc

    um, if the switch function operates depending on the value of $_GET['mod'], then sure. there's no reason why you couldn't call a different function depending on the value of that variable.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Godzone, oops Oz
    Posts
    355

    Re: Calling a function in a class from an html doc

    Quote Originally Posted by kows View Post
    um, if the switch function operates depending on the value of $_GET['mod'], then sure. there's no reason why you couldn't call a different function depending on the value of that variable.
    kows really wanting to know if I can call a function in a class via the same method. The only example I have is one php script calling another, which is slightly too advance for stage 1 of my super duper software considering the example uses templates and the like. Would rather push that to stage 2 and simply focus on getting the functionality working like a brought one.

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Calling a function in a class from an html doc

    then, do you mean that you want to have $_GET['mod'] be available within your class? it's a superglobal (meaning it's available in all scopes), so it should work fine.

    if this has nothing to do with what you're talking about, then please post an example of the switch function you'd like to be using. I just don't understand what else you could be trying to do from your description.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Godzone, oops Oz
    Posts
    355

    Re: Calling a function in a class from an html doc

    Quote Originally Posted by kows View Post
    then, do you mean that you want to have $_GET['mod'] be available within your class? it's a superglobal (meaning it's available in all scopes), so it should work fine.

    if this has nothing to do with what you're talking about, then please post an example of the switch function you'd like to be using. I just don't understand what else you could be trying to do from your description.
    The switch function works fine and dandy, however currently we have to repeat code, db connections etc, in each function and am trying to get around that by wrapping everything in a class and using declares at the top. Was wondering if I called a function from a html document would it matter if the function was part of a class?

    Hope that makes more sense.

  6. #6
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Calling a function in a class from an html doc

    it wouldn't matter if the class file was included in the "html" file (I hope you mean PHP by this!).

    you should never need to repeat database connections, though. I'm not sure if the connection -is- global, but even if it isn't, you could make the database connection (which would be declared publicly) available to your functions by using the "global" method.

    PHP Code:
    function test($sql){
      global 
    $myconnection;
      
    mysql_query($sql$myconnection);

    or, you could probably even pass the connection to the function. either way! :)

Posting Permissions

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



Click Here to Expand Forum to Full Width