Darkmatter5 Posted February 19, 2009 Share Posted February 19, 2009 I have a file that contains all my custom functions that is included in my php pages. Now within my php page I have some PHP code that I need to echo a function. Here's the code <?php for($i=1;$i<=10;$i++) { echo "<div id='bldlvl$i' style='background-color: yellow; width: 100%; clear: both; border-top: 1px gray dashed; display:none;'><p><?php $aftermath->listings(buildings,$i,edit); ?></div>"; } ?> Obviously the running of $aftermath->listings won't work as the echo thinks the ?> inside the echo is the end of the <?php tag. So it stops the code prematurely. How can I do this correctly? Quote Link to comment https://forums.phpfreaks.com/topic/145975-solved-echoing-syntax-help/ Share on other sites More sharing options...
omfgthezerg Posted February 19, 2009 Share Posted February 19, 2009 Not 100% sure what you want to do but I think this is what you want? <?php for($i=1;$i<=10;$i++) { echo '<div id=\'bldlvl'.$i.'\' style=\'background-color: yellow; width: 100%; clear: both; border-top: 1px gray dashed; display:none;\'><p><?php $aftermath->listings(buildings,'.$i.',edit); ?></div>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/145975-solved-echoing-syntax-help/#findComment-766342 Share on other sites More sharing options...
JonnoTheDev Posted February 19, 2009 Share Posted February 19, 2009 <?php for($i=1;$i<=10;$i++) { echo "<div id='bldlvl".$i."' style='background-color: yellow; width: 100%; clear: both; border-top: 1px gray dashed; display:none;'><p>".$aftermath->listings('buildings',$i,'edit')."</div>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/145975-solved-echoing-syntax-help/#findComment-766345 Share on other sites More sharing options...
premiso Posted February 19, 2009 Share Posted February 19, 2009 I think he meant like this bud. echo '<div id="bldlvl' . $i . '" style="background-color: yellow; width: 100%; clear: both; border-top: 1px gray dashed; display:none;"><p>' . $aftermath->listings('buildings',$i,'edit') . '</div>'; To actually use the function to print it out, not print the function to the screen. As far as "buildings" and "edit", I think you want them encapsulated in quotes. So i took the liberty to do that, but I may be wrong. EDIT: Neil beat me to it, oh well Quote Link to comment https://forums.phpfreaks.com/topic/145975-solved-echoing-syntax-help/#findComment-766347 Share on other sites More sharing options...
Darkmatter5 Posted February 19, 2009 Author Share Posted February 19, 2009 Basically I'm needing this <?php for($i=1;$i<=10;$i++) { echo "<div id='bldlvl$i' style='background-color: yellow; width: 100%; clear: both; border-top: 1px gray dashed; display:none;'><p>"; $aftermath->listings(buildings,$i,edit); echo "</div>"; } ?> but I was wanting to do it in one line, without breaking from the echo to run listings. Quote Link to comment https://forums.phpfreaks.com/topic/145975-solved-echoing-syntax-help/#findComment-766368 Share on other sites More sharing options...
Philip Posted February 19, 2009 Share Posted February 19, 2009 echo "<div id='bldlvl$i' style='background-color: yellow; width: 100%; clear: both; border-top: 1px gray dashed; display:none;'><p>", $aftermath->listings(buildings,$i,edit), "</div>"; Should work just fine Quote Link to comment https://forums.phpfreaks.com/topic/145975-solved-echoing-syntax-help/#findComment-766373 Share on other sites More sharing options...
Darkmatter5 Posted February 19, 2009 Author Share Posted February 19, 2009 thanks worked great! Quote Link to comment https://forums.phpfreaks.com/topic/145975-solved-echoing-syntax-help/#findComment-766435 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.