...

View Full Version : Resolved function executing too early?



s2ooz
05-12-2009, 12:14 PM
Hi, I have a function called from another function, and it is executing too early, why would this occur?




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?

s2ooz
05-12-2009, 12:19 PM
I have changed it to this and it works - am I missing something obvious?


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

Fou-Lu
05-12-2009, 12:20 PM
Come again?
Can you post the parsed HTML please?

s2ooz
05-12-2009, 12:22 PM
sorry -



<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>

Fou-Lu
05-12-2009, 12:34 PM
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.

s2ooz
05-12-2009, 02:51 PM
That makes logical sense, thanks for explaining that to me.

Fou-Lu
05-12-2009, 04:30 PM
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....



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum