Ace Cantos
Ace Cantos

Reputation: 11

ID in an html tag inside a php script

<?php
  foreach ($myquery_domain->result() as $row ){
    $domain = $row->domain;
    $domain_id = $row->domain_id;
    echo '<tr>';
      echo '<td>';
        echo '<span class="flip_domain" id="$domain_id">+</span>'.$domain;
      echo '</td>';
    echo '</tr>';
?> 

Hi, I want my $domain_id to be the ID of my . Could Someone help me pls. Thank you.

Upvotes: 1

Views: 99

Answers (4)

Blender
Blender

Reputation: 298106

I like the readable syntax:

<?php
  foreach ($myquery_domain->result() as $row ){
    $domain = $row->domain;
    $domain_id = $row->domain_id;
?>

  <tr>
    <td>
      <span class="flip_domain" id="<?php echo $domain_id; ?>">+</span> <?php echo $domain; ?>
    </td>
  </tr>

<?php
  }
?>

Upvotes: 1

Matt Ball
Matt Ball

Reputation: 359776

Using single quotes for string literals means that PHP won't substitute variables for you. So, use double-quotes instead:

 echo "<span class='flip_domain' id='$domain_id'>+</span>".$domain;

Upvotes: 1

Zul
Zul

Reputation: 3608

<?php
  foreach ($myquery_domain->result() as $row ){
    $domain = $row->domain;
    $domain_id = $row->domain_id;
    echo '<tr>';
      echo '<td>';
        echo '<span class="flip_domain" id="'.$domain_id.'">+</span>'.$domain;
      echo '</td>';
    echo '</tr>';
?> 

Upvotes: 2

Joseph Silber
Joseph Silber

Reputation: 219920

You'll have to concatenate it with a . - same as $domain:

echo '<span class="flip_domain" id="'.$domain_id.'">+</span>'.$domain;

Upvotes: 1

Related Questions