Click here to Skip to main content
15,560,542 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try to print table in php when I click on button then 2 table print
I tried this but it shows me undefine error on line 6

What I have tried:

HTML
<html>
<head>
</head>
<body>
<button name="submit">print</button>
<?php define ('NUM' ,3);
for($i=1;$i<=10;$i++){
	echo $i*num;
	echo '<br>';
}
?>
</body>
</html></br>
Posted
Updated 20-Jan-22 8:20am
v5

Following code will print table of 3 on click Print but you can pass number as parameter to function to print for any number:

<button onclick="printTable()"> Print </button>

<script>
function printTable(){
var result ="<?php php_func(); ?>"
document.write(result);
}
</script>

<?php
function php_func(){
    $NUM = 3;
    for($i=1;$i<=10;$i++){
        $product = $i*$NUM;
        echo "$NUM * $i = $product" ;   
        echo '<br>';	 
    }
}
?>
 
Share this answer
 
<?php 

for ($x = 1; $x <= 10; $x++) {
    echo "2 * $x = ";  
	echo $x * 2 ;
	echo " <br> " ;
		
} 
?>
 
Share this answer
 
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>


<?php
echo "Hello World <br>";

$a = 2;

for ($i=1; $i <=10; $i++) {

echo "$a * " . $i . " = ". $i*2;
echo "<br>";
}

?>
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900