• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net

php mysql display columns as header

zerocool786

Active Member
I have data inserted into MYSQL like below

Name.....empid.....Description....quantity...
A.............1..............Vacation.........5
B............2...............Vacation.........9
A.............1..............Sick................4


I want to display like this on the webpage

Name....empid.....Vacation....Sick
A..............1...............5................4
B..............2...............9................0

How can I do this, buys using php mysql? Here is my code below

Code:
<?php
    include ("connection.php");
   
    if(isset($_POST["delete1"]))
    {
     $c = 0;
$sql = 'SELECT * FROM internalhrs WHERE description="Administration"';

mysql_select_db('XXX');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}

echo "



<table border='1'>
<tr>
<th>Name</th>
<th>Emp ID</th>
<th>Description</th>
<th>Quantity</th>
</tr>";



while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{




echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['empid'] . "</td>";
echo "<td>" . $row['description'] . "</td>";
echo "<td>" . $row['quantity'] . "</td>";
echo "</tr>";

 

}
echo "Loaded ";







$sql = 'SELECT * FROM internalhrs WHERE description="Statutory Holiday"';

mysql_select_db('XXX');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}



while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{




echo "<td>" . $row['description'] . "</td>";
echo "</tr>";

 

}
echo "Loaded ";


}

?>
thanks in advance
 

iBrightDev

Jay Street
NLC
NLC
Personally, don't waste the processing power to do something like that, but if you wanted to do it, just query the information_schema...

PHP:
SELECT `COLUMN_NAME`
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`='yourdatabasename'
    AND `TABLE_NAME`='yourtablename';
 
Top