Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    17
    Thanks
    5
    Thanked 1 Time in 1 Post

    function executing too early?

    Hi, I have a function called from another function, and it is executing too early, why would this occur?

    PHP Code:

    echo '<div class="submenu">
        <ul>
            <li>'
    colourchoice($range_select). '</li>
            <li><a href="#">Accessories</a></li>
            <li><a href="#">backing</a></li>
        </ul>'
    ;

    function 
    colourchoice($range_select)
        {
            
    $query 'SELECT * FROM `catalogue` WHERE `range` = "'.$range_select.'" GROUP BY `style` ORDER BY `range`, `style` ';
            
    $result mysql_query($query) or die(mysql_error()); 
            
    $row mysql_fetch_array($result);
            echo 
    '<a href="colours.php?=somethinghere">'$row['3'].' Colour Choices</a>';

        } 
    but the out put is the link outside (before) the LI and a blank LI

    why would this happen?
    Last edited by s2ooz; 05-12-2009 at 01:52 PM.

  • #2
    New Coder
    Join Date
    May 2009
    Posts
    17
    Thanks
    5
    Thanked 1 Time in 1 Post
    I have changed it to this and it works - am I missing something obvious?
    PHP Code:
        <ul>
            <
    li>';
            colourchoice($range_select);
            echo '
    </li>
            <
    li><a href="#">Accessories</a></li>
            <
    li><a href="#">backing glass</a></li>
        </
    ul>
        </
    div>; 

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Come again?
    Can you post the parsed HTML please?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    New Coder
    Join Date
    May 2009
    Posts
    17
    Thanks
    5
    Thanked 1 Time in 1 Post
    sorry -

    PHP Code:
    <a href="colours.php?=somethinghere">ghent_gl.jpg Colour Choices</a><div class="submenu">
        <
    ul>
            <
    li></li>
            <
    li><a href="#">Accessories</a></li>
            <
    li><a href="#">backing glass</a></li>

        </
    ul>
        </
    div

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    No problem.
    Its because you're echo'ing within the echo.
    So, the logic is like this:
    echo .... --> (func call(echo....)). Since the outer echo has not completed, the output stack is given priority on the function call.
    To make it work prior to that, change the function to return that result instead of echoing it.

    Sorry I missed that on first look over.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    s2ooz (05-12-2009)

  • #6
    New Coder
    Join Date
    May 2009
    Posts
    17
    Thanks
    5
    Thanked 1 Time in 1 Post
    That makes logical sense, thanks for explaining that to me.

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by s2ooz View Post
    That makes logical sense, thanks for explaining that to me.
    You're welcome.
    I don't know how you could understand the little diagram I made there; I can't even make sense of it >.<
    I wonder what it was I was trying to draw....
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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