i want to print a php variable in the html h1 tag. Important thing to know is that html is defined within the php as follow:
<?php
$test=" <html>
<h1><?php echo (rand(10,1000000)); ?></h1>
</html> ";
echo $test;
?>
i want to print a php variable in the html h1 tag. Important thing to know is that html is defined within the php as follow:
<?php
$test=" <html>
<h1><?php echo (rand(10,1000000)); ?></h1>
</html> ";
echo $test;
?>
You can write either 1:
<?php
$a="hi";
?>
<html>
<h1><?php echo $a;?> </h1>
</html>
or 2:
<?php
$a="hi";
echo "<html><h1>".$a."</h1></html>";
?>
use the following
<?php
$a="hi";
$prints =" <html>
<h1> $a</h1>
</html>";
echo"$prints";
?>
You can directly 'show' php variables by 'echoing' them in the html. For example consider this code.
<?php
include_once "./php/db.php";
$result=$conn->query("SELECT * FROM medtable");
while($row=mysqli_fetch_array($result)){
echo '<form id="form-'.$row["Product"].'"type="POST">';
echo '<table class="table table-hover table-condensed" id="table-'.$row["Product"].'">';
echo '<tr>';
echo'<td style="width:50%" name="name-'.$row["Product"].'">'.$row["Product"].'</td>';
echo '<td style="width:20%"> <input type="number" name="amount" id="num-'.$row["Product"].'" min="0" value="'.$row['Amount'].'"</input></td>';
echo '<td style="width:10%">'.$row["Price"]. '</td>';
echo '<td id="subtotal-'.$row["Product"].'"style="width:10%" value="'.$row["Subtotal"].'">'.$row["Subtotal"].'</td><input type="hidden" name="hidden-'.$row['Product'].'"id="hidden-'.$row["Product"].'"value="'.$row["Subtotal"].'"</input>';
echo '<td style="width:10%"><input type="button"id="'.$row["Product"].'"
name="'.$row["Product"].'"class="btn btn-primary" value="Submit">
</input></td>';
echo '<td><input type="hidden" name="product" value="'.$row["Product"].'"></input></td>';
echo "</tr>";
echo "</table></form>";
}
?>
As you can see a query is made from a table and html tags are then echod into the html file. Hope this helps :)