-6

Is it possible to output <?php ?> output in echo? So the situation is this:

<?php
  // some code
  foreach ( $something as $row )
  {
     echo '<input type="hidden" id="'.$row["id"].'" value="<?php echo $cats; ?>">'
  }
 ?>

So how to output $cats in the value php part? Is it possible at all? I need the value that $cats hold not the whole part whit htmlentities

edit:

It is not duplicate and it is not '.$cats.' may be it's my fold that I didn't explain properly.

$cats got its value from response of ajax script not from this query

John
  • 171
  • 1
  • 2
  • 12

2 Answers2

8

No need of that tag again. Simply concatenate the variable -

echo '<input type="hidden" id="'.$row["id"].'" value="' . $cats . '">'

Update

With jQuery -

var response = "The response after ajax request";
$('input[type="hidden"]').val(response); // Selector will depend on your code
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
1

Since you're already in a PHP block, you don't need to open new php tags.

Try this instead.

<?php
  // some code
  foreach ( $something as $row )
  {
     echo '<input type="hidden" id="'.$row["id"].'" value="'.$cats.'">'
}?>
mituw16
  • 5,126
  • 3
  • 23
  • 48