Tuesday, March 3, 2015

Pascal Triangle in PHP

In this short tutorial I will show you how to create a Pascal Triangle Checker in PHP. What is program will do is very simple it will ask the user to enter a number and then our program will generate the corresponding Pascal Triangle Numbers based on the given number by our user.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360




Sample Output of Our Program

Program Listing

<html>
<title> Pascal Triangle Checker</title>
<style>
body { 
  font-size:25px; 
  font-family:arial;
  color:blue;
  } 
  
#banner {
  width: 750px;
  background-color: yellow;
  height: 100px;
  margin: 0 auto;
  position: inherit;
  top: 100; 
  left: 0; 
  bottom:0; 
  right: 0;
  padding: 16px 16px;
  
  border-radius: 75px;
  border: 5px solid #fba827;
}
  /* BUTTONS */

#submit {
  background: #0a7d66;
  background-image: -moz-linear-gradient(#0fb493, #0a7d66);
  background-image: -webkit-gradient(linear,left bottom,left top,color-stop(0, #6cbb6b),color-stop(1, #0fb493));
  
  margin: 0 0 0 2px;
  padding: 15px 20px;

  border-radius: 3px 70px 70px 3px;
  -moz-border-radius: 3px 70px 70px 3px;
  border-color: #0fb493 #0da284 #0c9075;

  -moz-box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
  -webkit-box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
  box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;  

  font: 16px 'Droid Serif', serif;
  background: #0fb493;
  color: blue;
  cursor: pointer;

  text-shadow: 0 5px 0 rgba(255,255,255,0.4);
}

#submit:hover {       
    background-color: #0fb493;
    background-image: linear-gradient(#0a7d66, #0fb493);
}   

#submit:active {       
    background: #0fb493;
    outline: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;        
}

#submit::-moz-focus-inner {
       border: 0;  /* Small centering fix for Firefox */
}
.inputs {
    -webkit-border-radius: 20px 3px 3px 20px;
    -moz-border-radius: 20px 3px 3px 20px;
    -ms-border-radius: 20px 3px 3px 20px;
    -o-border-radius: 20px 3px 3px 20px;
    border-radius: 20px 3px 3px 20px;

    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -ms-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;
    background: yellow;
    border: 5px solid #fba827;
    color: blue;
    font: 22px 'Droid Serif', serif;
    margin: 0 0 10px;
    padding: 15px 20px 15px 20px;
    width: 150px; 
}
</style>
<?php
error_reporting(0);
$values = $_POST['value'];

 if(isset($_POST['clear'])) {
  $title=""; 
  $values=" "; 
  $results="";
  $mess="";

}
 
if(isset($_POST['check'])) {


    if (ctype_alpha($values)) {
      echo "<script>";  
  echo "alert('PLEASE ENTER A NUMERIC VALUE.');";
  echo "</script>";
  $values="";
  $title=""; 
  
 }
    else  if ($values=="") {
      echo "<script>";  
  echo "alert('It Cannot Be Empty!!! Please enter a integer value.');";
  echo "</script>";
  $title=""; 
  $values="";

  
 }
   }  


?>
<body style='background-color:lightgreen'>
<div style='width:800px;margin:auto'>
   <div id="banner">
          <h1 align="center">Pascal Triangle Checker</h1>
      </div>
  <br>
<form action="" method="post">
 Enter a Number : <input id="text" type="text" class="inputs"  type="text" name="value"    value="<?php echo $values; ?>" autofocus  size=5 required/>
   <input  id="submit"  type="submit"  name="check" value="Check Pascal Triangle" 
  title="Click here check for Pascal Triangle Values."/>
  <input id="submit"  type="submit" name="clear" value="Clear" 
  title="Click here to clear text box and values on the screen"/>
</form>

<?php 
echo "<br>";
$rows=$values;
$coef=1;
$space=0;
$a=0;
$j=0;
    
    for($a=0;$a<$rows;$a++)
    {
        for($space=1;$space<=$rows-$a;$space++)
        echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        for($j=0;$j<=$a;$j++)
        {
            if ($j==0||$a==0)
                $coef=1;
            else
               $coef=$coef*($a-$j+1)/$j;
echo "<font size='6' face='arial'>";   
            echo " &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
     .$coef."&nbsp;&nbsp";
echo "</font>";
        }
        echo "<br>";
    }
 
?>
  </body>
</html>



Monday, March 2, 2015

Armstrong Number Checker in PHP

In this short tutorial I would like to share with you sample program to check whether the given number by the user is an armstrong number of not. What our program will do is to ask the user to enter a number and then the user can select the find armstrong number by click the button. Our sample program will also check if the user has entered number or not by using PHP character validation functions. I hope you will find my work useful in your learning in PHP programming.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360




Sample Output of Our Program

Program Listing

<html>
<title> Armstrong Number Checker</title>
<style>
body { 
  font-size:25px; 
  font-family:arial;
  color:blue;
  } 
  
#banner {
  width: 750px;
  background-color: yellow;
  height: 100px;
  margin: 0 auto;
  position: inherit;
  top: 100; 
  left: 0; 
  bottom:0; 
  right: 0;
  padding: 16px 16px;
  
  border-radius: 75px;
  border: 5px solid #fba827;
}
  /* BUTTONS */

#submit {
  background: #0a7d66;
  background-image: -moz-linear-gradient(#0fb493, #0a7d66);
  background-image: -webkit-gradient(linear,left bottom,left top,color-stop(0, #6cbb6b),color-stop(1, #0fb493));
  
  margin: 0 0 0 2px;
  padding: 15px 20px;

  border-radius: 3px 70px 70px 3px;
  -moz-border-radius: 3px 70px 70px 3px;
  border-color: #0fb493 #0da284 #0c9075;

  -moz-box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
  -webkit-box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
  box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;  

  font: 16px 'Droid Serif', serif;
  background: #0fb493;
  color: blue;
  cursor: pointer;

  text-shadow: 0 5px 0 rgba(255,255,255,0.4);
}

#submit:hover {       
    background-color: #0fb493;
    background-image: linear-gradient(#0a7d66, #0fb493);
}   

#submit:active {       
    background: #0fb493;
    outline: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;        
}

#submit::-moz-focus-inner {
       border: 0;  /* Small centering fix for Firefox */
}
.inputs {
    -webkit-border-radius: 20px 3px 3px 20px;
    -moz-border-radius: 20px 3px 3px 20px;
    -ms-border-radius: 20px 3px 3px 20px;
    -o-border-radius: 20px 3px 3px 20px;
    border-radius: 20px 3px 3px 20px;

    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -ms-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;
    background: yellow;
    border: 5px solid #fba827;
    color: blue;
    font: 22px 'Droid Serif', serif;
    margin: 0 0 10px;
    padding: 15px 20px 15px 20px;
    width: 150px; 
}
</style>
<?php
error_reporting(0);
$values = $_POST['value'];

 if(isset($_POST['clear'])) {
  $title=""; 
  $values=" "; 
  $results="";
  $mess="";

}

if(isset($_POST['check'])) {

$title = "======= The Result =======";
    if (ctype_alpha($values)) {
      echo "<script>";  
  echo "alert('PLEASE ENTER A NUMERIC VALUE.');";
  echo "</script>";
  $values="";
  $title=""; 
           $results="";
  $mess=" ";
 }
    else  if ($values=="") {
      echo "<script>";  
  echo "alert('It Cannot Be Empty!!! Please enter a integer value.');";
  echo "</script>";
  $title=""; 
  $values="";
           $results="";
  $mess=" ";
 }
   }  


?>
<body style='background-color:lightgreen'>
<div style='width:800px;margin:auto'>
   <div id="banner">
          <h1 align="center">Armstrong Number Checker</h1>
      </div>
  <br>
<form action="" method="post">
 Enter a Number : <input id="text" type="text" class="inputs"  type="text" name="value"    value="<?php echo $values; ?>" autofocus  size=5 required/>
   <input  id="submit"  type="submit"  name="check" value="Check Armstrong Number" 
  title="Click here check if the given number is an armstrong."/>
  <input id="submit"  type="submit" name="clear" value="Clear" 
  title="Click here to clear text box and values on the screen"/>
</form>

<?php 
 echo $title;
echo "<br>";

 $temp=$values;
  while($temp!=0)
     {
 $rem=$temp%10;
 $sum=$sum+$rem*$rem*$rem;
 $temp=$temp/10;
    }
 if($values==$sum)
  {
$mess = "is a Armstrong Number.";
$results = $values. " ".$mess;
}
else
{
$mess = "is Not an Armstrong Number.";
$results =  $values." ".$mess; 
}
 echo '<br>';
 echo $results;

 ?>
  </body>
</html>

Friday, February 27, 2015

Floyd's Triangle Maker

In this short article I would like to share with you a sample program that I wrote using PHP as our programming language I called this program Floyd's Triangle Maker what this program will do is to ask the user to enter a number and then it will generate the floyd's triangle on our screen. To give you some insights floyd's triangle was developed by an american computer scientist and mathematician named Robert Floyd. 

According to Wikipedia Floyd's Triangle is a right-angled triangular array of natural numbers, used in computer science education. It is defined by filling the rows of the triangle with consecutive numbers, starting with a 1 in the top left corner.

1
2    3
4    5     6
7     8     9  10
11  12  13  14 15

Sample of Floyd's Triangle

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360



Sample Output of Our Program

Program Listing

<html>
<title> Floyd's Triangle Maker</title>
<style>
body { 
  font-size:20px; 
  font-family:arial;
  color:blue;
  } 
</style>
<?php

$values = $_POST['value'];

 function floyds_triangle($variable) 
{
 $a = 1;   
 for ($i = 1; $i <= $variable; $i++)
  {
    for ($c = 1; $c <= $i; $c++)
    {
      echo " ".$a." ";
      $a++;
    }
  echo '<br><br>';
  }
     
}


if(isset($_POST['check'])) {

$title = "======= FLOYD'S TRIAGLE =======";
    if (ctype_alpha($values)) {
      echo "<script>";  
  echo "alert('PLEASE ENTER A NUMERIC VALUE.');";
  echo "</script>";
  $values="";
  $title=""; 
           $result="";
 }
    else  if ($values=="") {
      echo "<script>";  
  echo "alert('It Cannot Be Empty!!! Please enter a integer value.');";
  echo "</script>";
  $title=""; 
  $values="";
           $result="";
 }
   }  

if(isset($_POST['clear'])) {
  $title=""; 
  $values=" "; 
  $result="";
  
}

?>
<body style='background-color:lightgreen'>
<div style='width:800px;margin:auto'>
  <br> <h1 align="center">Floyd's Triangle Maker</h2>
  <br>
<form action="" method="post">
 Enter a Number : <input type="text" name="value"    value="<?php echo $values; ?>" autofocus  size=5 required/>
   <input type="submit" name="check" value="Find Floyd's Triangle" 
  title="Click here to view the list of Floyd's Triangle Number."/>
  <input type="submit" name="clear" value="Clear" 
  title="Click here to clear text box and values on the screen"/>
</form>

<br> <br>

<?php 

echo $title;
echo "<br><br>";
floyds_triangle($values); 

 ?>
 </body>
</html>



Thursday, February 26, 2015

Calculator Using Radio Buttons in PHP

One of the most enjoying past time that I would like to spend is to write a program it becomes one of my favorite hobbies during my college days. In this article I would like to share with you one of the most common programming problems in PHP how to write a simple calculator using radio buttons in PHP. Some of us think this kind of problem is very simple yes they are for some people who has already learned some experience in PHP programming but for some that are new in PHP problem it can gives us some headache if you don't how to figure it out. Our program will ask the user to enter two number in our text field and then our program will provide four radio buttons addition, subtraction, multiplication and division. Once the user select for example addition and click the solve button it will display the sum of the two numbers. I also added a clear button that enables the user to clear the text field and allows them to enter new values. 

The challenge that I face in writing this program is that I want to keep or retain the value of my selection radio button for example the addition radio button I want to retain its value after i click the solve button. In this program you will know how to accomplish such task with each. I have a great time writing this program I hope you will find my work useful in your quest in learning PHP programming.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360



Sample Output of Our Program

Program Listing

<head>
<?php
error_reporting(0);

 $first = $_REQUEST['first'];
 $second= $_REQUEST['second'];

 $first2 = (int)$first;
 $second2 = (int)$second;


if (isset($_REQUEST['solve'])) {
      
 $op = $_REQUEST['op'];
    
if ($op == 'add') {
 
   $add = $first2 + $second2;
 
 $title .="The sum of ".$first2. " and " .$second2. 
          " is " .$add.".";
     }  
if ($op == 'subtract') {
 
   $subtract = $first2 - $second2;
 
 $title .="The difference between ".$first2. " and " .$second2. 
          " is " .$subtract.".";
$op = ' checked="checked"';
     }    

if ($op == 'times') {
 
   $product = $first2 * $second2;
 
 $title .="The product of ".$first2. " and " .$second2. 
          " is " .$product.".";
     }    
if ($op == 'divide') {
 
   $quotient = $first2 / $second2;
 
 $title .="The quotient of ".$first2. " and " .$second2. 
          " is " .$quotient.".";
     }  
}  
 
    if(isset($_REQUEST['clear'])) {
      $first2 = " ";
      $second2 = " ";
      $result= " ";
   }
?>

<title>Calculator in PHP</title>
</head>
<style>
body {
     background-color: lightgreen;
font-family:arial;
font-style:bold;
font-size:22px; 
     font-family:arial;
     color:blue;
}
  
input
{
  -moz-border-radius: 15px;
    border-radius: 15px;
    border:solid 3px BLUE;
    padding:8px;
}
input {
  display: table-cell;
}

 label{
    display: table-cell;
    text-align: justify;
}
div.row{
    display:table-row;
}

/***FIRST STYLE THE BUTTON***/
button#gobutton{
cursor:pointer; /*forces the cursor to change to a hand when the button is hovered*/
padding:5px 25px; /*add some padding to the inside of the button*/
background:white; /*the colour of the button*/
border:1px solid #33842a; /*required or the default border for the browser will appear*/
/*give the button curved corners, alter the size as required*/
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
/*give the button a drop shadow*/
-webkit-box-shadow: 0 0 4px rgba(0,0,0, .75);
-moz-box-shadow: 0 0 4px rgba(0,0,0, .75);
box-shadow: 0 0 4px rgba(0,0,0, .75);
/*style the text*/
color:blue;
font-size:1.1em;
}
/***NOW STYLE THE BUTTON'S HOVER AND FOCUS STATES***/
button#gobutton:hover, button#gobutton:focus{
background-color :brown; /*make the background a little darker*/
/*reduce the drop shadow size to give a pushed button effect*/
-webkit-box-shadow: 0 0 1px rgba(0,0,0, .75);
-moz-box-shadow: 0 0 1px rgba(0,0,0, .75);
box-shadow: 0 0 1px rgba(0,0,0, .75);
}

 </style>

<body>

<div style='width:800px;margin:auto'>
<form>
<H2> Calculator in PHP </h2>
<div class="row"><label> FIRST VALUE 
<input type="text" id="first" name="first" placeholder="enter first value"
 value="<?php echo $first; ?>" autofocus required size=10></label></div><br>
<div class="row"> <label> SECOND VALUE
<input type="text" id="second" name="second" placeholder="enter second value"
 value="<?php echo $second; ?>" autofocus required size=10></label> </div>
<br>
<input type="radio" name="op"  value="add" <?php if($_REQUEST['op'] == "add") echo "checked"; ?>>ADDITION
<input type="radio" name="op"  value="subtract"  <?php if($_REQUEST['op'] == "subtract") echo "checked"; ?> >SUBTRACTION
<input type="radio" name="op"  value="times"  <?php if($_REQUEST['op'] == "times") echo "checked"; ?>>MULTIPLICATION
<input type="radio" name="op"  value="divide" <?php if($_REQUEST['op'] == "divide") echo "checked"; ?>>DIVISION
<br><br>
<button id="gobutton" type="submit" name="solve" id="solve" value="answer"
 title="Click here to find the result.">Solve</button>
<button id="gobutton" type="submit" name="clear" id="clear" value="answer"
title="Click here to clear text fields.">Clear</button>
</form>
<br> 
<?php
echo $title;
?>
</body> </div>
</html>