Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.