SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2001
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A function "nested" in another

    I've got an include_functionlist file with a list of all the fucntion my site is currently using.

    One of these functions:

    PHP Code:
    function draw_smalltable ($headline$body$base_image_url
    has numerous if statements with all telling to echo out another fucntion ala:

    PHP Code:
         if ($R == AND $i != mysql_num_rows($result))
              {
              
    draw_smalltable_loop($headline$body$base_image_url);
              echo 
    "</td><td>";        
              }
         elseif (
    $R == AND $i == mysql_num_rows($result))
              {
              
    draw_smalltable_loop($headline$body$base_image_url);
              echo 
    "</td></tr></table>";        
              } 
    // etc etc .. 
    I've also defined the draw_smalltable_loop fucntion somewhere in my function list file:

    PHP Code:
    function draw_smalltable_loop($headline$body$base_image_url
    In my php page I am making use the former function:

    PHP Code:
    draw_smalltable ("$section[2]""$section[5]"$base_image_url); 
    All the images are printed out fine with the only problem being the first two parameters of the function which are text-material are not printed in the tables.
    Any ideas, why?
    Bardius

  2. #2
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    variables aren't send through a function unless you make them global variables or if you send them through to the function using Function(vars)

    I think it might be something like that!!!

    Greets,

    Peanuts
    the neigbours (free) WIFI makes it just a little more fun

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2001
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not entirely sure on what you exactly mean. Could you a bit clearer please?
    Bardius

  4. #4
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Bardius
    Not entirely sure on what you exactly mean. Could you a bit clearer please?

    Check this out:

    http://www.phpbuilder.com/manual/lan...bles.scope.php

    It just says that if you have a function then within that function the values of all $variables don't just count ..

    So
    PHP Code:
    function my_function()
    {
    $a $b $c
    return $a

    now calling
    Code:
    <?
    my_function();
    ?>
    will give you nothing because the function needs input
    so :
    PHP Code:
    function my_function($b,$c)
    {
    $a $b $c
    return $a

    now calling
    Code:
    <?
    my_function("1","4");
    ?>
    Will give you $a = 5

    With globals you can get around all that.. see the phpbuilder manual (link above)
    Hope it helps..

    greets

    Peanuts
    the neigbours (free) WIFI makes it just a little more fun

  5. #5
    purple monkey dishwasher scoates's Avatar
    Join Date
    Nov 2001
    Location
    Montreal
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Variables aren't being passed to draw_smalltable_loop(...) properly; it might be because $headline and $body are common between the functions and the inner copy of the variables is overwriting the external version.

    Sorry, that's prolly not overly clear, but I hope it helps.

    S


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
  •