sir may tanong ako output na need is pascals triangle na nakatable meron ako code dito pero hindi siya ngaoutput. ano po kaya mali?salamat po.
<DOCTYPE html>
<html>
<head>
<title>Activity 2</title>
</head>
<body>
<form metho="post"></br>
Number of Rows:    <input type="text" name="numRow" required="">    <input type="submit" name="test" value="Display"><br>
</form>
<?php
function numRow()
{
$result = $_POST['numRow'];
for ($y = 0; $y < $result; $y ++)
{
for ($x = 1; $x <= $y; $x ++)
{
if($x == 1){
$result[$y][$x] = 1; // start with 1
echo "<table style=\"border: 1px solid black;\">";
echo "<tr>";
echo "<td>";
echo "$result";
echo "</td>";
echo "</tr>";
}elseif($x == $y){
$result[$y][$x] = 1; // end with 1
echo "<table style=\"border: 1px solid black;\">";
echo "<tr>";
echo "<td>";
echo "$result";
echo "</td>";
echo "</tr>";
}else{
$result[$y][$x] = $result[$y-1][$x-1] + $result[$y-1][$x];
echo "<table style=\"border: 1px solid black;\">";
echo "<tr>";
echo "<td>";
echo "$result";
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
}
}
if (array_key_exists('test', $_POST)){
result();
}
?>
</body>
</html>
bossing, pasensya na bos mali ako ng post, php queries pala talaga yun. pero tinry ko code mo wala nga nag a output, try ko intindihin. sa ngayon try mo muna gawin basehan to bos
<DOCTYPE html>
<html>
<head>
<title>Activity 2</title>
</head>
<body>
<?php
# Pascal's Triangle using Recursion.
$rows_to_generate = 15; // Define number of rows you want to generate.
$storage = array();
function get_elem($row,$pos) // generate element having number of row and number of position.
{
global $storage;
if(isset($storage[$row][$pos]))
{
return $storage[$row][$pos];
}
if($row==1 and $pos==1) // for first row.
{
return 1;
}
else if($pos==0) // for left most row element that doesn't exist.
{
return 0;
}
else if($pos>$row) // for right most row element that doesn't exist.
{
return 0;
}
return get_elem($row-1,$pos-1)+get_elem($row-1,$pos); // Recursion
}
?>
<?php
$previous = array(1);
$next = array();
for($i=1; $i<=$rows_to_generate; $i++)
{
// the first element in each row is 1
$next[0] = 1;
for($j=1; $j<$i; $j++)
{
$next[$j] = $previous[$j] + $previous[$j-1];
}
echo implode(' ', $next) . '<br>';
$previous = $next;
$next = array();
// there is one more element in the new row than the old
$previous[] = 0;
}
?>
</body>
</html>