Saturday, June 30, 2012

Add Records to multiple tables php mysql



Add Records to multiple tables php mysql

We were discussed adding multiple records to a table in my previous post now we are going to add records in to multiple tables and joining of those table getting out put.Make following 3 tables in your my data base.

CREATE TABLE IF NOT EXISTS `divition` (
  `uid` int(40) NOT NULL AUTO_INCREMENT,
  `uname` varchar(45) NOT NULL,
  `division` varchar(45) NOT NULL,
  PRIMARY KEY (`uid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `institute` (
  `iid` int(30) NOT NULL,
  `institute` varchar(40) NOT NULL,
  PRIMARY KEY (`iid`),
  UNIQUE KEY `iid` (`iid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `job_title` (
  `tid` int(30) NOT NULL,
  `job_title` varchar(40) NOT NULL,
  PRIMARY KEY (`tid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Add records using a form as bellow

Name
Division
Institute
Job Title

Use following php codes to enter data into above 3 tables

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form1" id="form1" >
<table bgcolor=#5f5b0b>
  <tr bgcolor=#ffffff>
    <td >Name</td>
    <td>
      <input type="text" name="uname" size=65/>
    </td>
  </tr>
  <tr bgcolor=#ffffff>
    <td>Division</td>
    <td><input type="text" name="division" size=65 /></td>
  </tr>
  <tr bgcolor=#ffffff>
    <td>Institute</span></div></td>
    <td><input type="text" name="institute" size=65 /></td>
  </tr>
  <tr bgcolor=#ffffff>
    <td>Job Title</span></div></td>
    <td><input type="text" name="job_title" size=65 /></td>
  </tr>

 <tr bgcolor=#ffffff>
    <td colspan=2 align="right">
<input type="submit" name="save" value="Save Record"></td>
  </tr>  </table>
</form>
<?php
 $connection = mysql_connect ("localhost", "root","")
   or die  (mysql_error());

 mysql_select_db ("my_database");

  $uname=$_POST['uname'];
  $division=$_POST['division'];
  $institute=$_POST['institute'];
  $job_title=$_POST['job_title'];

 $query_1="INSERT INTO divition (uid, uname, division) VALUES (NULL, '$uname', '$division')";
  mysql_query($query_1);
 $lastid=mysql_insert_id();

$query_2="INSERT INTO institute (iid, institute) VALUES ($lastid, '$institute')";
  mysql_query($query_2);
  $query_3="INSERT INTO job_title (tid, job_title) VALUES ($lastid, '$job_title')";
  mysql_query($query_3);

  mysql_close($connection);
 
 echo "Records Added";
 ?>

Use following codes to display the records in 3 tables in single table

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("my_database",$con);
$query='SELECT divition.uname, divition.division, institute.institute,
        job_title.job_title
        FROM divition,institute,job_title
        WHERE divition.uid = institute.iid
        AND divition.uid = job_title.tid' ;
$result = mysql_query($query);

while ($row = mysql_fetch_assoc($result)){
    echo "name".$row['uname']." <br> ";
      echo "Division :".$row['division']." <br> ";
       echo "Institute:".$row['institute']."<br> ";
        echo  "Job Title:".$row['job_title']."<br>";
      
}

mysql_close($con);
?>

Thursday, June 28, 2012

Simple Search Engine php


Simple Search Engine php

I have mentioned in previous tutorials how to search data in a database.Now we can move on to making simple search engine.For this tutorial also need to have data base table called search.Make search table in your my_database using following guide.

CREATE TABLE IF NOT EXISTS `search` (
  `id` int(40) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `link` varchar(255) NOT NULL,
  `description` longtext NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


Then make search input file called search.php


wintekweb php

free php scripts,wintekweb.blogspot.com/2012/06/joining-3-tables-php-mysql.html 8 Jun 2012 ?

Get Visitors IP Address PHP - wintekweb php

free php scripts,wintekweb.blogspot.com/2012/05/get-visitors-ip-address-php.html 30 May 2012 ? web statistic is very important when you start your own site.web statistics mainly consist of page views today,yesterday,last month &all history ...

AND Search php - wintekweb php

free php scripts,5 Jun 2012 ? Php scripts,php mysql,Create Database ,Drop Database,Create Database, Incert, Displaying Data, PHP MySQL Update.

<html>
<head>
<title>Search Engine
</title>
</head>
<body>
<form name="form" method="post"  action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table align="center">
<tr><td colospan=2><img src="win.png"></td></tr>
<tr><td><input name="search" type="text" id="search" size="50"></td><td><input type="submit" name="Submit" value="Search &gt;&gt;"></td></tr>
</table>
</form>
<?php
$search=$_POST['search'];
$con = mysql_connect("localhost","root","","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("my_database", $con);

$result=mysql_query("select * from search WHERE title LIKE '%$search%' OR description LIKE '%$search%'");
$num_rows = mysql_num_rows($result);

while ($row = mysql_fetch_assoc($result)){
echo "<font color=#418dce><H4><a href=$row[link]>".$row['title']."</a></H4></font>";
echo $row['description']."</br>";
}
?>
</body>
</html>

Monday, June 25, 2012

standard deviation php

standard deviation php

Standard Deviation

The Standard Deviation is a measure of how spread out numbers are.Its symbol is σ (the greek letter sigma). By using php you can find Standard Deviation in this example,I have created only for 10 numbers you expand it to any numbers you need.Here example 1 for population and example 2 is for sample.
example 1
standard deviation = 21.282856951077
Values


<?php
$num1=$_POST['val1'];
$num2=$_POST['val2'];
$num3=$_POST['val3'];
$num4=$_POST['val4'];
$num5=$_POST['val5'];
$num6=$_POST['val6'];
$num7=$_POST['val7'];
$num8=$_POST['val8'];
$num9=$_POST['val9'];
$num10=$_POST['val10'];
function standard_deviation_population ($a)
{
 
  $the_standard_deviation = 0.0;
  $the_variance = 0.0;
  $the_mean = 0.0;
  $the_array_sum = array_sum($a); //sum the elements
  $number_elements = count($a); //count the number of elements


  $the_mean = $the_array_sum / $number_elements;


  for ($i = 0; $i < $number_elements; $i++)
  {

    $the_variance = $the_variance + ($a[$i] - $the_mean) * ($a[$i] - $the_mean);
  }

  $the_variance = $the_variance / $number_elements;


  $the_standard_deviation = pow( $the_variance, 0.5);


  return $the_standard_deviation;
}
$a = array($num1, $num2, $num3, $num4, $num5, $num6,$num7,$num8,$num9,$num10);

$standard_deviation = standard_deviation_population ($a);

echo "standard_deviation = $standard_deviation<br>";
?>
<table bgcolor=#d38a2a>
<form name="calc" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<tr bgcolor=#ffffff><td>Values</td></tr>
<tr bgcolor=#ffffff><td><input type="text" name="val1"></td></tr>
<tr bgcolor=#ffffff><td><input type="text" name="val2"></td></tr>
<tr bgcolor=#ffffff><td><input type="text" name="val3"></td></tr>
<tr bgcolor=#ffffff><td><input type="text" name="val4"></td></tr>
<tr bgcolor=#ffffff><td><input type="text" name="val5"></td></tr>
<tr bgcolor=#ffffff><td><input type="text" name="val6"></td></tr>
<tr bgcolor=#ffffff><td><input type="text" name="val7"></td></tr>
<tr bgcolor=#ffffff><td><input type="text" name="val8"></td></tr>
<tr bgcolor=#ffffff><td><input type="text" name="val9"></td></tr>
<tr bgcolor=#ffffff><td><input type="text" name="val10"></td></tr>
<tr bgcolor=#ffffff><tr bgcolor=#ffffff><td><input type="submit" vaue="Calculate"></td></tr>
</form>
</table>

Example2 

<?php
function standard_deviation_sample ($a)
{

  $the_standard_deviation = 0.0;
  $the_variance = 0.0;
  $the_mean = 0.0;
  $the_array_sum = array_sum($a);
  $number_elements = count($a);


  $the_mean = $the_array_sum / $number_elements;


  for ($i = 0; $i < $number_elements; $i++)
  {

    $the_variance = $the_variance + ($a[$i] - $the_mean) * ($a[$i] - $the_mean);
  }

  $the_variance = $the_variance / ($number_elements - 1.0);


  $the_standard_deviation = pow( $the_variance, 0.5);


  return $the_standard_deviation;
}

$a = array(0, 1, 2, 3, 4, 5);

$standard_deviation = standard_deviation_sample ($a);

echo "a[0] = $a[0]<br>";
echo "a[1] = $a[1]<br>";
echo "a[2] = $a[2]<br>";
echo "a[3] = $a[3]<br>";
echo "a[4] = $a[4]<br>";
echo "a[5] = $a[5]<br>";
echo "standard_deviation = $standard_deviation<br>";
?>

Tuesday, June 19, 2012

Resizing Images php

Resizing Images php
Resizing images also could be done with php.Some programs in php we have to use previously created files for different proposes as libraries.In here too,I have used such previously created files  for this program.
I used the same image kid.png and bellow shows you the needed files for this progam.
  • kid.png
  • resize.php
  • resize-class.php

WidthHeight


resize.php

<table bgcolor=#d38a2a>
<tr bgcolor=#ffffff>
<form name="f1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<tr bgcolor=#ffffff><td>Width</td><td>Height</td></tr>
<td ><input type="text" name="width"></td>
<td><input type="text" name="height"></td></tr>
<tr bgcolor=#ffffff>
<td colspan=2><input type="submit" value="Resize"></td>
</tr></form></table>
<?php
$width=$_POST['width'];
$height=$_POST['height'];
include("resize-class.php");
$resizeObj = new resize('kid.png');
$resizeObj -> resizeImage($width, $height, 'crop');
$resizeObj -> saveImage('resized.jpg', 100);
echo "<img src='resized.jpg'>";
?>

resize-class.php

<?php

 

        Class resize
        {
          
            private $image;
            private $width;
            private $height;
            private $imageResized;

            function __construct($fileName)
            {
              
                $this->image = $this->openImage($fileName);

             
                $this->width  = imagesx($this->image);
                $this->height = imagesy($this->image);
            }

      

            private function openImage($file)
            {
                // *** Get extension
                $extension = strtolower(strrchr($file, '.'));

                switch($extension)
                {
                    case '.jpg':
                    case '.jpeg':
                        $img = @imagecreatefromjpeg($file);
                        break;
                    case '.gif':
                        $img = @imagecreatefromgif($file);
                        break;
                    case '.png':
                        $img = @imagecreatefrompng($file);
                        break;
                    default:
                        $img = false;
                        break;
                }
                return $img;
            }

      

            public function resizeImage($newWidth, $newHeight, $option="auto")
            {
                // *** Get optimal width and height - based on $option
                $optionArray = $this->getDimensions($newWidth, $newHeight, $option);

                $optimalWidth  = $optionArray['optimalWidth'];
                $optimalHeight = $optionArray['optimalHeight'];


                // *** Resample - create image canvas of x, y size
                $this->imageResized = imagecreatetruecolor($optimalWidth, $optimalHeight);
                imagecopyresampled($this->imageResized, $this->image, 0, 0, 0, 0, $optimalWidth, $optimalHeight, $this->width, $this->height);


                // *** if option is 'crop', then crop too
                if ($option == 'crop') {
                    $this->crop($optimalWidth, $optimalHeight, $newWidth, $newHeight);
                }
            }

      
          
            private function getDimensions($newWidth, $newHeight, $option)
            {

               switch ($option)
                {
                    case 'exact':
                        $optimalWidth = $newWidth;
                        $optimalHeight= $newHeight;
                        break;
                    case 'portrait':
                        $optimalWidth = $this->getSizeByFixedHeight($newHeight);
                        $optimalHeight= $newHeight;
                        break;
                    case 'landscape':
                        $optimalWidth = $newWidth;
                        $optimalHeight= $this->getSizeByFixedWidth($newWidth);
                        break;
                    case 'auto':
                        $optionArray = $this->getSizeByAuto($newWidth, $newHeight);
                        $optimalWidth = $optionArray['optimalWidth'];
                        $optimalHeight = $optionArray['optimalHeight'];
                        break;
                    case 'crop':
                        $optionArray = $this->getOptimalCrop($newWidth, $newHeight);
                        $optimalWidth = $optionArray['optimalWidth'];
                        $optimalHeight = $optionArray['optimalHeight'];
                        break;
                }
                return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
            }

          

            private function getSizeByFixedHeight($newHeight)
            {
                $ratio = $this->width / $this->height;
                $newWidth = $newHeight * $ratio;
                return $newWidth;
            }

            private function getSizeByFixedWidth($newWidth)
            {
                $ratio = $this->height / $this->width;
                $newHeight = $newWidth * $ratio;
                return $newHeight;
            }

            private function getSizeByAuto($newWidth, $newHeight)
            {
                if ($this->height < $this->width)
                // *** Image to be resized is wider (landscape)
                {
                    $optimalWidth = $newWidth;
                    $optimalHeight= $this->getSizeByFixedWidth($newWidth);
                }
                elseif ($this->height > $this->width)
                // *** Image to be resized is taller (portrait)
                {
                    $optimalWidth = $this->getSizeByFixedHeight($newHeight);
                    $optimalHeight= $newHeight;
                }
                else
              
                {
                    if ($newHeight < $newWidth) {
                        $optimalWidth = $newWidth;
                        $optimalHeight= $this->getSizeByFixedWidth($newWidth);
                    } else if ($newHeight > $newWidth) {
                        $optimalWidth = $this->getSizeByFixedHeight($newHeight);
                        $optimalHeight= $newHeight;
                    } else {
                        // *** Sqaure being resized to a square
                        $optimalWidth = $newWidth;
                        $optimalHeight= $newHeight;
                    }
                }

                return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
            }

          

            private function getOptimalCrop($newWidth, $newHeight)
            {

                $heightRatio = $this->height / $newHeight;
                $widthRatio  = $this->width /  $newWidth;

                if ($heightRatio < $widthRatio) {
                    $optimalRatio = $heightRatio;
                } else {
                    $optimalRatio = $widthRatio;
                }

                $optimalHeight = $this->height / $optimalRatio;
                $optimalWidth  = $this->width  / $optimalRatio;

                return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
            }

      

            private function crop($optimalWidth, $optimalHeight, $newWidth, $newHeight)
            {
              
                $cropStartX = ( $optimalWidth / 2) - ( $newWidth /2 );
                $cropStartY = ( $optimalHeight/ 2) - ( $newHeight/2 );

                $crop = $this->imageResized;
                //imagedestroy($this->imageResized);

                // *** Now crop from center to exact requested size
                $this->imageResized = imagecreatetruecolor($newWidth , $newHeight);
                imagecopyresampled($this->imageResized, $crop , 0, 0, $cropStartX, $cropStartY, $newWidth, $newHeight , $newWidth, $newHeight);
            }

          

            public function saveImage($savePath, $imageQuality="100")
            {
                // *** Get extension
                $extension = strrchr($savePath, '.');
                   $extension = strtolower($extension);

                switch($extension)
                {
                    case '.jpg':
                    case '.jpeg':
                        if (imagetypes() & IMG_JPG) {
                            imagejpeg($this->imageResized, $savePath, $imageQuality);
                        }
                        break;

                    case '.gif':
                        if (imagetypes() & IMG_GIF) {
                            imagegif($this->imageResized, $savePath);
                        }
                        break;

                    case '.png':
                        // *** Scale quality from 0-100 to 0-9
                        $scaleQuality = round(($imageQuality/100) * 9);

                        // *** Invert quality setting as 0 is best, not 9
                        $invertScaleQuality = 9 - $scaleQuality;

                        if (imagetypes() & IMG_PNG) {
                             imagepng($this->imageResized, $savePath, $invertScaleQuality);
                        }
                        break;

                    // ... etc

                    default:
                      
                        break;
                }

                imagedestroy($this->imageResized);
            }


          

        }
?>

Image Filters php

Image Filters php

You may have lot of experiences with image filters using in image processing soft wares.By using php also you can add filters to a image create following php file and get experienced with.
Interface image and codes are bellow.For example, I have taken here created a folder named "mod" in root directory and used a kid.png image for adding filter effects.Brite

Value1
Value2
Value3
Operation:-Brightness GRAY SCALE

CONTRASTCOLORIZE

Edge EffectsEMBOSS

GAUSSIAN BLURMEAN REMOVAL

SMOOTHNEGATE

gray scale to colorizeSELECTIVE BLUR
Emboss Image

Codes are bellow.
<html>
<title>
</title>
<body>

<table bgcolor=#d38a2a>
<form name="calc" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<tr bgcolor=#ffffff><td align="center" colspan=3><img src="kid.png"></td></tr>
<tr bgcolor=#ffffff><td colspan=2>Value1</td><td><input type="text" name="value1"></td></tr>
<tr bgcolor=#ffffff><td colspan=2>Value2</td><td><input type="text" name="value2"></td></tr>
<tr bgcolor=#ffffff><td colspan=2>Value3</td><td><input type="text" name="value3"></td></tr>
<tr bgcolor=#ffffff><td>Operation:-</td><td><input type="radio" name="oper" value="brv">Briteness</td><td><input type="radio" name="oper" value="gry">GRAYSCALE</td></tr>
<tr bgcolor=#ffffff><td>&nbsp;</td><td><input type="radio" name="oper" value="cont">CONTRAST</td><td><input type="radio" name="oper" value="col">COLORIZE</td></tr>
<tr bgcolor=#ffffff><td>&nbsp;</td><td><input type="radio" name="oper" value="ege">Edge Effects</td><td><input type="radio" name="oper" value="emb">EMBOSS</td></tr>
<tr bgcolor=#ffffff><td>&nbsp;</td><td><input type="radio" name="oper" value="gau">GAUSSIAN BLUR</td><td><input type="radio" name="oper" value="mrm">MEAN REMOVAL</td></tr>
<tr bgcolor=#ffffff><td>&nbsp;</td><td><input type="radio" name="oper" value="smth">SMOOTH</td><td><input type="radio" name="oper" value="neg">NEGATE</td></tr>
<tr bgcolor=#ffffff><td>&nbsp;</td><td><input type="radio" name="oper" value="grco">grayscale to colorize</td><td><input type="radio" name="oper" value="sblur">SELECTIVE BLUR</input></td></tr>
<tr bgcolor=#ffffff><td colspan=3 align="right"><input type="submit" value="Add Filter"></td></tr>
</form>
</table>
</table>
</form>
<?php

$val=$_POST['value1'];
$val2=$_POST['value2'];
$val3=$_POST['value3'];
$oper=$_POST['oper'];

if($oper=='brv'){

$image = imagecreatefrompng('kid.png');
imagefilter($image, IMG_FILTER_BRIGHTNESS,$val);
imagepng($image, 'mod/img_filter_brightness_5.png');
imagedestroy($image);
echo "Briteness Added Image</br><img src='mod/img_filter_brightness_5.png'>";
}
else if($oper=='gry'){

$image = imagecreatefrompng('kid.png');
imagefilter($image, IMG_FILTER_GRAYSCALE);
imagepng($image, 'mod/img_filter_grayscale.png');
imagedestroy($image);
echo "Gray Scaled Image</br><img src='mod/img_filter_grayscale.png'>";
}
else if($oper=='cont'){

$image = imagecreatefrompng('kid.png');
imagefilter($image, IMG_FILTER_CONTRAST, $val);
imagepng($image, 'mod/img_filter_contrast_5.png');
imagedestroy($image);
echo "Contrast Added Image</br><img src='mod/img_filter_contrast_5.png'>";
}
else if($oper=='col'){
$image = imagecreatefrompng('kid.png');
imagefilter($image, IMG_FILTER_COLORIZE, $val, $val2, $val3);
imagepng($image, 'mod/img_filter_colorize_100_0_0.png');
imagedestroy($image);
echo "Colorized Image</br><img src='mod/img_filter_colorize_100_0_0.png'>";
}
else if($oper=='emb'){
$image = imagecreatefrompng('kid.png');
imagefilter($image, IMG_FILTER_EMBOSS);
imagepng($image, 'mod/img_filter_emboss.png');
imagedestroy($image);
echo "Emboss Image</br><img src='mod/img_filter_emboss.png'>";
}
else if($oper=='ege'){
$image = imagecreatefrompng('kid.png');
imagefilter($image, IMG_FILTER_EDGEDETECT);
imagepng($image, 'mod/img_filter_edgedetect.png');
imagedestroy($image);
echo "Edge Detect Image</br><img src='mod/img_filter_edgedetect.png'>";
}
else if($oper=='gau'){
$image = imagecreatefrompng('kid.png');
imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
imagepng($image, 'mod/img_filter_gaussian_blur.png');
imagedestroy($image);
echo "Gaussian blur Image</br><img src='mod/img_filter_gaussian_blur.png'>";
}
else if($oper=='mrm'){
$image = imagecreatefrompng('kid.png');
imagefilter($image, IMG_FILTER_MEAN_REMOVAL);
imagepng($image, 'mod/img_filter_mean_removal.png');
imagedestroy($image);
echo "Mean Removed Image</br><img src='mod/img_filter_mean_removal.png'>";
}
else if($oper=='smth'){
$image = imagecreatefrompng('kid.png');
imagefilter($image, IMG_FILTER_SMOOTH, $val);
imagepng($image, 'mod/img_filter_smooth_5.png');
imagedestroy($image);
echo "Smooth Image</br><img src='mod/img_filter_smooth_5.png'>";
}
else if($oper=='neg'){
$image = imagecreatefrompng('kid.png');
imagefilter($image, IMG_FILTER_NEGATE);
imagepng($image, 'mod/img_filter_negate.png');
imagedestroy($image);
echo "Negate Image</br><img src='mod/img_filter_negate.png'>";
}
else if($oper=='grco'){
$image = imagecreatefrompng('kid.png');
imagefilter($image, IMG_FILTER_GRAYSCALE);
imagefilter($image, IMG_FILTER_COLORIZE,$val,$val2,$val3);
imagepng($image, 'mod/sepia_100_50_0.png');
imagedestroy($image);
echo "colorize Image</br><img src='mod/sepia_100_50_0.png'>";
}
else if($oper=='sblur'){
$image = imagecreatefrompng('kid.png');
imagefilter($image, IMG_FILTER_SELECTIVE_BLUR);
imagepng($image, 'mod/img_filter_selective_blur.png');
imagedestroy($image);
echo "Selective Blur Image</br><img src='mod/img_filter_selective_blur.png'>";
}
else
{
echo "<font color='red'>Fialed!</font>";
}
?>
</body>
</html>

Sunday, June 17, 2012

Displaying mysql 2 php

Displaying mysql page 2 php

Previous page we were discussed 2 ways of displaying mysql data.Here, I am going to show you the other methods of  displaying data. I used my_database table biodata. following files show you the other ways of displaying mysql data.
Example:-01
<table border=1><tr><td>First Name</td><td>Last Name</td><td>Age</td></tr>
<?php

$dbHost = 'localhost';

$dbUser = 'root';

$dbPass = '';

$dbName = 'my_database';

$dbConn = mysql_connect ($dbHost,$dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error());

mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error());

$query = "SELECT * FROM biodata";

$result = mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while($i<$num){

$FirstName=mysql_result($result,$i,1);
$LastName=mysql_result($result,$i,2);
$Age=mysql_result($result,$i,3);
?>

<tr><td><?php echo $FirstName;?></td><td><?php echo $LastName;?></td><td><?php echo $Age;?></td></tr>
<?php
++$i;
}
?>
</table>

Example:-02

<table border=1><tr><td>First Name</td><td>Last Name</td><td>Age</td></tr>
<?php

$dbHost = 'localhost';

$dbUser = 'root';

$dbPass = '';

$dbName = 'my_database';

$dbConn = mysql_connect ($dbHost,$dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error());

mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error());

$Query="SELECT * from biodata";
$dbresult=mysql_query($Query);
if(mysql_num_rows($dbresult) >0) {
while($row=mysql_fetch_row($dbresult)) {
?>
<tr><td><?php echo $row[1];?></td><td><?php echo $row[2];?></td><td><?php echo $row[3];?></td></tr>
<?php
}
}
?>
</table>
Next

Calender php

Calender php


There are inbuilt programs for incorporating  calender in to your website or blog site.But you may need to learn how to build your own calender.Here, I have displayed you very simple type of calender you can build and customized to your need.

June 2012
SundayMondayTuesdayWednesdayThursdayFridaySaturday





1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
<?php
$date =time () ;
$day = date('d', $date) ;
$month = date('m', $date) ;
$year = date('Y', $date) ;
$first_day = mktime(0,0,0,$month, 1, $year) ;
$title = date('F', $first_day) ;

 $day_of_week = date('D', $first_day) ;

switch($day_of_week){

 case "Sun": $blank = 0; break;

 case "Mon": $blank = 1; break;

 case "Tue": $blank = 2; break;

 case "Wed": $blank = 3; break;

 case "Thu": $blank = 4; break;

 case "Fri": $blank = 5; break;

 case "Sat": $blank = 6; break;

 }

 $days_in_month = cal_days_in_month(0, $month, $year) ;

echo "<table bgcolor=#138e61>";

 echo "<tr bgcolor=#138e61><th colspan=7><font color=#ffffff> $title $year</font> </th></tr>";

 echo "<tr bgcolor=#e8f2ee><th >Sunday</th><th >Monday</th><th >Tuesday</td><th>Wednesday</th><th>Thursday</th><th
>Friday</th><th>Saturday</th></tr>";
$day_count = 1;
echo "<tr bgcolor=#e8f2ee>";
while ( $blank > 0 )

 {

 echo "<td></td>";

 $blank = $blank-1;

 $day_count++;

 }

$day_num = 1;
while ( $day_num <= $days_in_month )

 {

 echo "<td> $day_num </td>";

 $day_num++;

 $day_count++;


 if ($day_count > 7)

 {

 echo "</tr><tr bgcolor=#e8f2ee>";

 $day_count = 1;

 }

 }

 while ( $day_count >1 && $day_count <=7 )

 {

 echo "<td> </td>";

 $day_count++;

 }


 echo "</tr></table>";
?>

Date and Birthday php



Date and Birthday php

Reading the positional numbers in a date
Reading the positional numbers use php substr() function. For an example take the date 2012-10- 17 add the date into substr() function. as bellow.

<?php
$num="2012-06-17";
echo "year:-". substr($num, 0, 4)."</br>";
echo "Month:-". substr($num, 5,2)."</br>";
echo "Date:-". substr($num, 8, 2)."</br>";
?>
Output is
year:-2012
Month:-06
Date:-17

Get Birthday in years 
You can get age in years by using codes bellow.

<?php
$Birthdate="1965-06-12";
 function GetAge($Birthdate)
{
     
        list($BirthYear,$BirthMonth,$BirthDay) = explode("-", $Birthdate);
        $YearDiff = date("Y") - $BirthYear;
        $MonthDiff = date("m") - $BirthMonth;
        $DayDiff = date("d") - $BirthDay;
         if ($DayDiff < 0 || $MonthDiff < 0)
          $YearDiff--;
        return $YearDiff;
}
echo GetAge($Birthdate)." "."Years Old";

?>
Output is
47 Years Old

Get Birthday in days,month and years 
Execute the following codes to get birthday in details with your input of birthday.

Bith Day
Click To Find Age
Age47 years and 5 days old
<form name="f1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table bgcolor=#d38a2a align="center"><tr bgcolor=#ffffff><td>Bith Day</td><td><input type="text" name="bday"></td></tr>
<tr bgcolor=#ffffff><td>Click To Find Age</td><td align="right"><input type="submit" value="Find"></td></tr>
</form>
<?php
$bday=$_POST['bday'];
function get_Age_difference($start_date,$end_date){
    list($start_year,$start_month,$start_date) = split('-', $start_date);
    list($current_year,$current_month,$current_date) = split('-', $end_date);
     $result = '';
 for($x=1 ; $x<=12 ; $x++){

        $dim[$x] = date('t',mktime(0,0,0,$x,1,date('Y')));

    }
    $m = $current_month - $start_month;
    $d = $current_date - $start_date;
    $y = $current_year - $start_year;
if($d < 0) {
    
        $today_day = $current_date + $dim[$current_month];
        $today_month = $current_month - 1;
        $d = $today_day - $start_date;
        $m = $today_month - $start_month;
        if(($today_month - $start_month) < 0) {

            $today_month += 12;
            $today_year = $current_year - 1;
            $m = $today_month - $start_month;
            $y = $today_year - $start_year;

        }

    }

 if($m < 0) {

        $today_month = $current_month + 12;
        $today_year = $current_year - 1;
        $m = $today_month - $start_month;
        $y = $today_year - $start_year;

        }

  if($y < 0) {

        die("Start Date Entered is a Future date than End Date.");

    } else {

        switch($y) {

            case 0 : $result .= ''; break;
            case 1 : $result .= $y.($m == 0 && $d == 0 ? ' year old' : ' year'); break;
            default : $result .= $y.($m == 0 && $d == 0 ? ' years old' : ' years');

        }


        switch($m) {

            case 0: $result .= ''; break;
            case 1: $result .= ($y == 0 && $d == 0 ? $m.' month old' : ($y == 0 && $d != 0 ? $m.' month' : ($y != 0 && $d == 0 ? ' and '.$m.' month old' : ', '.$m.' month'))); break;
            default: $result .= ($y == 0 && $d == 0 ? $m.' months old' : ($y == 0 && $d != 0 ? $m.' months' : ($y != 0 && $d == 0 ? ' and '.$m.' months old' : ', '.$m.' months'))); break;

        }


        switch($d) {

            case 0: $result .= ($m == 0 && $y == 0 ? 'Today' : ''); break;
            case 1: $result .= ($m == 0 && $y == 0 ? $d.' day old' : ($y != 0 || $m != 0 ? ' and '.$d.' day old' : '')); break;
            default: $result .= ($m == 0 && $y == 0 ? $d.' days old' : ($y != 0 || $m != 0 ? ' and '.$d.' days old' : ''));

        }

    }

    return $result;

}
 $date_difference= get_Age_difference($bday,date("Y-m-d"));

echo "<tr bgcolor=#ffffff><td>Age</td><td>".$date_difference."</td></tr></table>";
?>
Next

Saturday, June 16, 2012

Date,Birth Day & calender php

Date,Birth Day & calender php


Different ways of date display,I have included in following table you can change order of letters and make different ways of display in your own.

m/d/y06/16/12
m/d/Y06/16/2012
n/j/Y6/16/2012
M/j/YJun/16/2012
F/j/YJune/16/2012
M/D/YJun/Sat/2012
Y / M / D2012 / Jun / Sat
y - M - D12 - Jun - Sat
y - M - d12 - Jun - 16
Y - M - d2012 - Jun - 16
Y - F - d2012 -June- 16
d -F- Y16 -June- 2012
d -M- Y16 -Jun- 2012
d -m- Y16 -06- 2012
d -m- Y16 -06- 12
d -n- Y16 -6- 12
j -n- Y16 -6- 12

For creating above table following codes are needed.

<?php
echo "<table bgcolor=#ff9900><tr bgcolor=#ffffff><td>m/d/y</td><td>".date("m/d/y")."</td></tr>";
echo "<table bgcolor=#ff9900><tr bgcolor=#ffffff><td>m/d/Y</td><td>".date("m/d/Y")."</td></tr>";
echo "<table bgcolor=#ff9900><tr bgcolor=#ffffff><td>n/j/Y</td><td>".date("n/j/Y")."</td></tr>";
echo "<table bgcolor=#ff9900><tr bgcolor=#ffffff><td>M/j/Y</td><td>".date("M/j/Y")."</td></tr>";
echo "<table bgcolor=#ff9900><tr bgcolor=#ffffff><td>F/j/Y</td><td>".date("F/j/Y")."</td></tr>";
echo "<tr bgcolor=#ffffff><td>M/D/Y</td><td>".date("M/D/Y")."</td></tr>";
echo "<table bgcolor=#ff9900><tr bgcolor=#ffffff><td>Y / M / D</td><td>".date("Y / M / D")."</td></tr>";
echo "<table bgcolor=#ff9900><tr bgcolor=#ffffff><td>y - M - D</td><td>".date("y - M - D")."</td></tr>";
echo "<table bgcolor=#ff9900><tr bgcolor=#ffffff><td>y - M - d</td><td>".date("y - M - d")."</td></tr>";
echo "<table bgcolor=#ff9900><tr bgcolor=#ffffff><td>Y - M - d</td><td>".date("Y - M - d")."</td></tr>";
echo "<table bgcolor=#ff9900><tr bgcolor=#ffffff><td>Y - F - d</td><td>".date("Y -F- d")."</td></tr>";
echo "<table bgcolor=#ff9900><tr bgcolor=#ffffff><td>d -F- Y</td><td>".date("d -F- Y")."</td></tr>";
echo "<table bgcolor=#ff9900><tr bgcolor=#ffffff><td>d -M- Y</td><td>".date("d -M- Y")."</td></tr>";
echo "<table bgcolor=#ff9900><tr bgcolor=#ffffff><td>d -m- Y</td><td>".date("d -m- Y")."</td></tr>";
echo "<table bgcolor=#ff9900><tr bgcolor=#ffffff><td>d -m- Y</td><td>".date("d -m- y")."</td></tr>";
echo "<table bgcolor=#ff9900><tr bgcolor=#ffffff><td>d -n- Y</td><td>".date("d -n- y")."</td></tr>";
echo "<table bgcolor=#ff9900><tr bgcolor=#ffffff><td>j -n- Y</td><td>".date("j -n- y")."</td></tr>";
echo "</table>";
?>

Find Leap Years


leap day is a date that occurs in most years that are evenly divisible by 4.In Leap year month of February ends with 29 days.By creating the following php file you could find the year you have entered is a leap year or not.
File HTML Layout and codes are bellow.
Year
Click Find
Febuary end date2013-02-28
<?php
$year=$_POST['year'];
function last_day_of_feb ($year) {

        $ultimo_feb_str = $year . "-03-00";
        $ultimo_feb_date = date_create($ultimo_feb_str);
        $return = date_format($ultimo_feb_date, "Y-m-d");
        return $return;
}
?>
<form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table bgcolor=#d38a2a align="center"><tr bgcolor=#ffffff><td>Year</td><td><input type="text" name="year"></td></tr>
<tr bgcolor=#ffffff><td>Click Find</td><td align="right"><input type="submit" value="Find"></td></tr>
<tr bgcolor=#ffffff><td>Febuary end date</td><td align="right"><?php echo last_day_of_feb($year); ?></td></tr>
</table>
</form>

Adding Number of days to a given date 

Calculations with the dates are different with other numerical calculations because month have 1-28/31days while year having 12 months.Following example shows you how to add number of days in to a date(today).


<?php
echo date('Y-m-d', strtotime("+164 days"));
?>
out put is
2012-11-27


Powered by Moon Calendar













Free Calendar & Clock
Next

Monday, June 11, 2012

Number Converter php

Number Converter php
This tutorial ,I have included complete number converter.Interface as follows.

Number
Operation:-Binary to DecimalBinary to Octal

Binary to HexadecimalDecimal to Binary

Decimal to OctalDecimal to Hexadecimal

Octal to BinaryOctal to Decimal

Octal to hexadecimalHexadecimal to binary

Hexadecimal to DecimalHexadecimal to Octal

PHP codes are bellow

<table bgcolor=#d38a2a>
<form name="calc" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<tr bgcolor=#ffffff><td>Number </td><td><input type="text" name="value1"><td align="center"><img src="cal.png"></td></tr>
<tr bgcolor=#ffffff><td>Operation:-</td><td><input type="radio" name="oper" value="bdec">Binary to Decimal</td><td><input type="radio" name="oper" value="boct">Binary to Octal</td></tr>
<tr bgcolor=#ffffff><td>&nbsp;</td><td><input type="radio" name="oper" value="bhex">Binary to Hexadecimal</td><td><input type="radio" name="oper" value="dbin">Decimal to Binary</td></tr>
<tr bgcolor=#ffffff><td>&nbsp;</td><td><input type="radio" name="oper" value="doct">Decimal to Octal</td><td><input type="radio" name="oper" value="dhex">Decimal to Hexadecimal</td></tr>
<tr bgcolor=#ffffff><td>&nbsp;</td><td><input type="radio" name="oper" value="obin">Octal to Binary</td><td><input type="radio" name="oper" value="odec">Octal to Decimal</td></tr>
<tr bgcolor=#ffffff><td>&nbsp;</td><td><input type="radio" name="oper" value="ohex">Octal to hexadecimal</td><td><input type="radio" name="oper" value="hbin">Hexadecimal to binary</td></tr>
<tr bgcolor=#ffffff><td>&nbsp;</td><td><input type="radio" name="oper" value="hdec">Hexadecimal to Decimal</td><td><input type="radio" name="oper" value="hoct">Hexadecimal to Octal</input></td></tr>
<tr bgcolor=#ffffff><td colspan=3 align="right"><input type="submit" value="Calculate"></td></tr>
</form>
</table>
<?php


$number1=$_POST['value1'];
$oper=$_POST['oper'];

if($oper=='bdec'){

$bin="$number1";
$dec= base_convert($bin,2,10);
echo "<font size=6 color='blue'><b>".$dec."</b></font>";

}
else if($oper=='boct'){

$bin="$number1";
$oct= base_convert($bin,2,8);
echo "<font size=6 color='blue'><b>".$oct."</b></font>";

}
else if($oper=='bhex'){

$bin="$number1";
$hex= base_convert($bin,2,16);
echo "<font size=6 color='blue'><b>". $hex."</b></font>";

}
else if($oper=='dbin'){
$dec="$number1";
$bin= base_convert($dec,10,2);
echo "<font size=6 color='blue'><b>". $bin."</b></font>";

}
else if($oper=='doct'){
$dec="$number1";
$oct= base_convert($dec,10,8);
echo "<font size=6 color='blue'><b>". $oct."</b></font>";
}
else if($oper=='dhex'){
$dec="$number1";
$hex= base_convert($dec,10,16);
echo "<font size=6 color='blue'><b>". $hex."</b></font>";
}
else if($oper=='obin'){
$oct="$number1";
$bin= base_convert($oct,8,2);
echo "<font size=6 color='blue'><b>". $bin."</b></font>";
}
else if($oper=='odec'){
$oct="$number1";
$dec= base_convert($oct,8,10);
echo "<font size=6 color='blue'><b>". $dec."</b></font>";
}
else if($oper=='ohex'){
$oct="$number1";
$hex= base_convert($oct,8,16);
echo "<font size=6 color='blue'><b>". $hex."</b></font>";
}
else if($oper=='hbin'){
$hex="$number1";
$bin= base_convert($hex,16,2);
echo "<font size=6 color='blue'><b>". $bin."</b></font>";
}
else if($oper=='hdec'){
$hex="$number1";
$dec= base_convert($hex,16,10);
echo "<font size=6 color='blue'><b>". $dec."</b></font>";
}
else if($oper=='hoct'){
$hex="$number1";
$oct= base_convert($hex,16,8);
echo "<font size=6 color='blue'><b>". $oct."</b></font>";
}
else
{
echo "<font color='red'>Wrong Input or Method</font>";
}
?>
Next

Calculator 2 php

Calculator 2 php

This tutorial ,I have included some of the mathematical functions which could not be included in tutorial simple calculator.although  some of number conversion is included here completed number conversion is included in next tutorial.
Calculator2  interface is bellow.

Number
Operation:-Bin_DECDec_Hex

Dec_OctDec_Bin

RoundOct_Dec

1/x

X2%

C

CosSin

Tan
Create and run the following scripts

<table bgcolor=#d38a2a>
<form name="calc" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<tr bgcolor=#ffffff><td>Number </td><td><input type="text" name="value1"><td align="center"><img src="cal.png"></td></tr>
<tr bgcolor=#ffffff><td>Operation:-</td><td><input type="radio" name="oper" value="bdec">Bin_DEC</td><td><input type="radio" name="oper" value="dhex">Dec_Hex</td></tr>
<tr bgcolor=#ffffff><td>&nbsp;</td><td><input type="radio" name="oper" value="doct">Dec_Oct</td><td><input type="radio" name="oper" value="dbin">Dec_Bin</td></tr>
<tr bgcolor=#ffffff><td>&nbsp;</td><td><input type="radio" name="oper" value="rd">Round</td><td><input type="radio" name="oper" value="odec">Oct_Dec</td></tr>
<tr bgcolor=#ffffff><td>&nbsp;</td><td><input type="radio" name="oper" value="sqr">√</td><td><input type="radio" name="oper" value="inv">1/x</input></td></tr>
<tr bgcolor=#ffffff><td>&nbsp;</td><td><input type="radio" name="oper" value="powd">X<sup>2</sup></td><td><input type="radio" name="oper" value="per">%</td></tr>
<tr bgcolor=#ffffff><td>&nbsp;</td><td><input type="radio" name="oper" value="pi">∏</td><td><input type="radio" name="oper" value="reset">C</td></tr>
<tr bgcolor=#ffffff><td>&nbsp;</td><td><input type="radio" name="oper" value="cos">Cos</td><td><input type="radio" name="oper" value="sin">Sin</td></tr>
<tr bgcolor=#ffffff><td>&nbsp;</td><td><input type="radio" name="oper" value="tan">Tan</input></td><td>&nbsp;</td></tr>
<tr bgcolor=#ffffff><td colspan=3 align="right"><input type="submit" value="Calculate"></td></tr>
</form>
</table>
<?php


$number1=$_POST['value1'];
$oper=$_POST['oper'];

if($oper=='bdec'){

echo bindec("$number1");

}
else if($oper=='dhex'){

echo dechex("$number1");

}
else if($oper=='doct'){

echo decoct("$number1");

}
else if($oper=='dbin'){
echo decbin("$number1");

}
else if($oper=='rd'){
echo round("$number1");
}
else if($oper=='odec'){
echo octdec("$number1");
}
else if($oper=='sqr'){
echo sqrt("$number1");
}
else if($oper=='inv'){
$result=1/$number1;
echo $result;
}
else if($oper=='powd'){
$result=$number1*$number1;
echo $result;
}
else if($oper=='per'){
$result=$number1/100;
echo $result;
}
else if($oper=='pi'){
echo pi();
}
else if($oper=='reset'){
echo "field is cleared";
}
else if($oper=='cos'){
echo cos($number1);
}
else if($oper=='sin'){
echo sin($number1);
}
else if($oper=='tan'){
echo tan($number1);
}
else
{
echo "<font color='red'>Wrong Input or Method</font>";
}
?>
Next