Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

[TUT]PHP Procedural.

kyleharveyeclevia

Recruit
Basic Member
Messages
17
Reaction score
1
Points
18
Hello Symbianizers at mga ka PHP
Kung may tanong kayo or kailangan nyo ng help regarding PHP Queries(procedural)
Just leave a comment below. I will do what I can to help :)
 
Last edited:
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:&nbsp&nbsp&nbsp <input type="text" name="numRow" required="">&nbsp&nbsp&nbsp <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>
 
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:&nbsp&nbsp&nbsp <input type="text" name="numRow" required="">&nbsp&nbsp&nbsp <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>
 
Paturo ng php Interface , Abstract , Namespace


SOLID PHP

S - Single-responsiblity principle
O - Open-closed principle
L - Liskov substitution principle
I - Interface segregation principle
D - Dependency Inversion Principle
 
Tama naman ito, nagdagdag lang ng extra for centering.

Note: Impossible ilagay ito sa table dahil hindi magsasakto ang mga cells dahil ang mabubuong shape dapat ay triangle, which is hindi kaya irender kapag pinilit sa table.

<DOCTYPE html>
<html>
<head>
<title>Activity 2</title>
</head>
<body style="text-align: center;">
<?php
echo '<pre>';

# 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;
}

echo '</pre>';
?>
</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>



salamat sa info sir. sige aralin ko to at try ko.
 
Back
Top Bottom