Results 1 to 2 of 2

Thread: Trying to create function that makes mysql call

  1. #1
    Join Date
    Oct 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Trying to create function that makes mysql call

    I want to use a user-defined variable that was created outside of a function INSIDE a function. How is this done?

    Example:

    $i = 0;

    function CreateFields () {

    echo "<div class=\"course" .$i. "\">";

    $i++;

    }

    CreateFields();

    but $i is not being recognized inside the function. Help?
    Last edited by junestag; 10-19-2009 at 07:32 PM. Reason: Need different question answered

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    PHP Code:
    $i 0;

    function 
    CreateFields($i) {

       echo 
    "<div class=\"course" .$i"\">";

       
    $i++;

       return 
    $i;  //sends the variable back *out* of the function
    // (if that's what you want: I can't think of any other reason you'd increment it's value)

    }

    CreateFields(); 

Bookmarks

Posting Permissions

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