How to use HTML and CSS into the PHP

How to use HTML and CSS into the PHP.

HTML with PHP

In this example, I am going to tell you, how to use HTML and CSS in your PHP script and make your web page more attractive.

In below example, we are using HTML and CSS in PHP script and print employs details in an effective manner. We are using the table in a PHP script and print serial number employees’ name and employs id.

You can also use this table and CSS at the time of retrieving the data from the database.

Syntax

<html>
<head>
<title> Employ name and ID</title>
<style>
th { text - align: left; background: #E6E6E6; }
th, td { padding:10px; }
tr.alt td { background: #EAEAEA; }
</style>
</head>
<body>
<h2> Print employ id in table using php</h2>
<table cellspacing="0" border="0" style="width: 20em; border: 1px solid
#666;">
<tr>
<th> Serial number  </th>
<th> Name  </th>
<th>Employ ID</th>
</tr>
<?php
$number_of_emp = 10;
$uk="pT-";
for ( $i=1; $i <= $number_of_emp; $i++ )
{
$num2= rand(1000,10000);
$num1 = $uk.$num2 ;
?>
<tr <?php if ( $i % 2 != 0 ) echo ' class="alt"' ?>>
<td> P <sub> <?php echo $i?> </sub> </td>
<td> <?php echo "Umar";?> </td>
<td> <?php echo $num1?> </td>
</tr>
<?php
}
?>
</table>
</body>
</html>


Explanation of PHP code

$number_of_emp is a simple integer type variable that holds the maximum number of employs limit after that create a random number and con concatenate with string for uniquely employs ID and assign to the $num1 variable.

Line number 5 decide the style of the table rows, if the number is even (mean number of rows) then the class “ALT” is called otherwise simply print without any style.

If you want to learn more about functions, classes, include, and function library please visit
php tutorial



The following two tabs change content below.
Umar Farooque Khan is Software developer and professional blogger serving Worldwide on freelancer and ODesk platform to show the capability of his skills. He is the founder of pTutorial.com. The main purpose of this site is sharing and exchanging of Knowledge related to the recent technologies.
This entry was posted in PHP on by .

About Umar Farooque Khan

Umar Farooque Khan is Software developer and professional blogger serving Worldwide on freelancer and ODesk platform to show the capability of his skills. He is the founder of pTutorial.com. The main purpose of this site is sharing and exchanging of Knowledge related to the recent technologies.