user3092953 user3092953 - 4 months ago 16
MySQL Question

Echo Variable inside of echo statement

I am trying to echo a php variable inside of a php echo statement.

I have a column in a MySql database called

display_code
which contains a value such as
$num_rows_customers
.

I am calling this from the DB as
displayCode


$displayCode = $row ['display_code'];


And trying to echo like this:

<?php
echo "<div class='col-md-3'>
$displayCode
</div>";

?>


However this is printing
$num_rows_customers
instead of a number

Is there a way to do this?

By the way, I already have this script on the page

<?php $result100=mysql_query("SELECT * FROM customers")or die('Error 27' . mysql_error());
$num_rows_customers = mysql_num_rows($result100);?>

Answer

About Variable variables read here

$displayCode = 'num_rows_customers';
$num_rows_customers = 10;  
           echo "<div class='col-md-3'>
           {$$displayCode}
           </div>";

demo

Comments