Sunday, June 22, 2008

PHP Round Off Decimal or Convert to Decimal Point

Round Off Decimal

Round a number up or down or Round off a floating decimal point number using PHP's functions round().

Example. round();


echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.05
echo round(5.055, 2); // 5.06
?>

Convert to Decimal Point

Example. number_format();


$number = "28";
$number = number_format($number, 2);
echo $number; // equals "28.00"
?>

Tuesday, April 29, 2008

MySQL Connection using PHP Script:

MySQL Connection using PHP Script:

PHP provides mysql_connect() function to open a database connection. This function takes five parameters and returns a MySQL link identifier on success, or FALSE on failure.

Syntax:

connection mysql_connect(server,user,passwd,new_link,client_flag);

You can disconnect from MySQL database anytime using another PHP function mysql_close(). This function takes a single parameter which is a connection returned by mysql_connect() function.

Syntax:

bool mysql_close ( resource $link_identifier );


Example:
<html> 
<head>
<title>Connecting MySQL Server</title>
</head>
<body>
<?php $dbhost = 'localhost:3036';
$dbuser = 'guest';
$dbpass = 'guest123';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';

mysql_close($conn);?>

</body></html>

Sunday, March 16, 2008

Choosing a hosting

Today there are many hosting services provided. Which one will you choose? Some may choose because of their price, additional services provided, reliability and etc. A good hosting service should be selected or else you want to suffer because of data loses or unavailability of the services.

Here you can find below what exactly to look for when choosing the best web hosting service.
Some aspect that you should take into consideration to choose right hosting servers:

  1. Amount of web space
  2. FTP access
  3. Degree of reliability, security and speed of access
  4. Data transfer (Bandwidth)
  5. Pricing

PHP Comparison Operators

Comparison Operator are use to compare between 2 variable. It will return true of false value.

Below are the common comparison operator use like other languages use.

Operator

Description

==

is equal to

!=

is not equal

>

is greater than

<

is less than

>=

is greater than or equal to

<=

is less than or equal to

PHP Arithmetic Operator

Below are the Arithmetic Operator use in PHP:

Operator

Description

+

Addition

-

Subtraction

*

Multiplication

/

Division

%

Modulus (division remainder)

++

Increment

--

Decrement

PHP Comment

In PHP, // is use to make a single-line comment or /* and */ to make a large comment block.

Examples:

<html>
<body>

<?php

//Single comment use //

/*
Block
comment
*/

?>

</body>
</html>

PHP Basic

PHP is a Server Side Scripting. It is embeded into the HTML code.

Basic code:

<html>
<?php echo "Hello World" ?>
</html>

The PHP code begin with the tag. The output of the code is Hellow World.

Wednesday, January 23, 2008

Display Current Directory Files

Apache usually will display the default web pages usually index.php or index.html where you had predefine in your configuration files. So how could we display other files easily? The best way to implement is that you create a file which will output all files in the directory. Below is example of how could u implement.

Save the as index.php


<html>

<?php

/**zfm
* Name this file index.php and place in the directory.
*/


//Data Initialization
$counter = 1;


// Define the full path to your folder from root
//$path = "put the full path here";
$path = "./.";

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");

echo "<font size=5>Directory folder</font><br><br>";

// Loop through the files
while ($file = readdir($dir_handle)) {

if($file == "." || $file == ".." || $file == "index.php" )

continue;
echo $counter." <a href=\"$file\">$file</a><br>";

$counter+=1;

}

// Close
closedir($dir_handle);

?>
</html>

Tuesday, January 22, 2008

Change Apache Listening Port

How to change Apache Listening port?
As default apache port was 80 or 8080. If the port had been use by other program the apache could not be started.

To change the default port to desired port, open the apache configuration file.
By default the file located at:
C:\Program Files\Apache Software Foundation\Apache2.2\conf

Open httpd.conf

Then find "Listen" Change the default number to your prefered number.

Eg: Listen 1000

Monday, January 21, 2008

PHP5 MYSQL5 APACHE 2.2

Recently PHP had been use widely.It was an Open Source product where the development of it continues for year until now. Dynamic scripting can be done easily, manipulating codes to do what we want and with many tools available to debug & run php, the popularity of php remained.

Lets us explore the world of php together.