Rahul Dev
Rahul Dev

Reputation: 71

Append html element in php like jQuery append

I know jQuery append element, but I want to know is there any way so that I can append 50 similar elements using php with some loop so something else, The elements I want to append 50 times are given here,

<div class='test'>
  <span class='<?php echo $result[0]->cc1;?>'><?php echo $result[0]->dd1;?></span>
</div>
  
<div class='test'>
  <span class='<?php echo $result[0]->cc2;?>'><?php echo $result[0]->dd2;?></span>
</div>
  
<div class='test'>
  <span class='<?php echo $result[0]->cc3;?>'><?php echo $result[0]->dd3;?></span>
</div>
  
<div class='test'>
  <span class='<?php echo $result[0]->cc4;?>'><?php echo $result[0]->dd4;?></span>
</div>
  
//  and so on.. up to 50.

Tried this but not working,

<?php for ($i=0; $i <50; $i++) : ?> <span class='<?php echo $result[0]->cc'+i+';?>'><?php echo $result[0]->dd'+i+';?></span> <?php endfor; ?>

Upvotes: 0

Views: 89

Answers (1)

RiggsFolly
RiggsFolly

Reputation: 94662

Create a loop

Then using the $result[0]->{'cc'.$i} syntax address all your properties

for( $i=1; $i<51; $i++) :
?>
    <div class='test'>
        <span class='<?php echo $result[0]->{'cc'.$i};?>'><?php echo $result[0]->{'dd'.$i};?></span>
    </div>
<?php
endfor;

Upvotes: 1

Related Questions