Jump to content

[SOLVED] echoing syntax help


Darkmatter5

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/145975-solved-echoing-syntax-help/
Share on other sites

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>';
  }
?>

<?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>";
  }
?>

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.