Hi,
Im new in this programming world. Here is my problem: I need to display result of which I need to show location and gred using colors. For example for total staff the color will be blue and green color for available post. Below is my coding but it will only display a list of location and position for each location. How do I do it in php? How do I calculate number of staff and put the result in table which will show in blue color?

Below is my code:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

</body>
</html><?php

//connect database
$con = mysql_connect("localhost","root");

if(!$con)
{
    die('Could not connect: ' . mysql_error());

}

//select database to be use
mysql_select_db("mpchr", $con);

// query the database table
$sql = "SELECT Floor_Location, GRED_ID FROM STAFF ";

//run the query againts the mysql function
$result=mysql_query($sql);

echo "<table border='1'>
<tr>
<th>\n\n\nLokasi</th>
<th>\n\n\n\n\n\n\n\n\n\n\n\nJawatan</th>
</tr>";

//ceate while loop and loop through result set
while ($row = mysql_fetch_array ($result))
{
    $Floor_Location= $row ['Floor_Location'];
    $Gred_ID = $row [ 'GRED_ID'];   

    //display the result of the array
    echo "<tr>";
    echo "<td> " . $row['Floor_Location'] . "</td>";
    echo "<td>"  . $row['GRED_ID'] . "</td>";
    echo "</tr>";

}

echo "</table>";

mysql_close($con);  

?>

Appreciate with any help frm you guys.

Member Avatar for rajarajan2017

Sample:

copy and paste and test the file to get the result, and implement in your code.

<html> 
<head> 
</head> 
<body> 
<?php 

// set quantity 
$quantity = 1000; 

// set original and current unit price 
$origPrice = 100; 
$currPrice = 25; 

// calculate difference in price 
$diffPrice = $currPrice - $origPrice; 

// calculate percentage change in price 
$diffPricePercent = (($currPrice - $origPrice) * 100) / $origPrice;

?> 

<table border="1" cellpadding="5" cellspacing="0"> 
<tr> 
<td>Quantity</td> 
<td>Cost price</td> 
<td>Current price</td> 
<td>Absolute change in price</td> 
<td>Percent change in price</td> 
</tr> 
<tr> 
<td><font color="red"><b><?php echo $quantity ?></b></font></td> 
<td><font color="green"><b><?php echo $origPrice ?></b></td> 
<td><font color="blue"><?php echo $currPrice ?></b></td> 
<td><font color="grey"><?php echo $diffPrice ?></b></td> 
<td><font color="yellow"><?php echo $diffPricePercent ?>%</b></td> 
</tr> 
</table> 

</body> 
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.