       
        <div class="CSSTableGenerator" >

            <p>
                <?php
                try {
                    $con = new PDO('mysql:host=localhost;port=3306;dbname=kimai', "kimai", "kimai");
                    $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                    //ALTER TABLE `kimai15_pct`
                    //ADD COLUMN `pct_billable` TINYINT(1) NOT NULL DEFAULT '0' AFTER `pct_internal`;
                    $query = <<<EOD
select DISTINCT
k.knd_name as 'Company Name',
p.pct_name as 'Project',
CASE
	WHEN p.pct_billable = 0 THEN CONCAT("<input type='radio' name='",p.pct_ID, "' value='0' checked='checked'/>")
	ELSE CONCAT("<input type='radio' name='",p.pct_ID, "' value='0'/>")
END as 'Billabale',
CASE
	WHEN p.pct_billable = 1 THEN CONCAT("<input type='radio' name='",p.pct_ID, "' value='1' checked='checked'/>")
	ELSE CONCAT("<input type='radio' name='",p.pct_ID, "' value='1'/>")
END as 'Non-billable',
CASE
	WHEN p.pct_billable = 2 THEN CONCAT("<input type='radio' name='",p.pct_ID, "' value='2' checked='checked'/>")
	ELSE CONCAT("<input type='radio' name='",p.pct_ID, "' value='2'/>")
END as 'Unproductive'	
from kimai15_pct p
inner join kimai15_knd k on p.pct_kndID=k.knd_ID
where p.pct_visible = 1
order by k.knd_name, p.pct_name         
EOD;

                    echo "<form method='post'>";
                    //first pass just gets the column names
                    echo '<table id="myTable" border="1" cellpadding="3" cellspacing="0">';
                    $result = $con->query($query);
                    //return only the first row (we only need field names)
                    $row = $result->fetch(PDO::FETCH_ASSOC);
                    echo " <tr> \n";
                    foreach ($row as $field => $value) {
                        echo " <th>$field</th> \n";
                    } // end foreach
                    echo " </tr> \n";
                    //second query gets the data
                    $data = $con->query($query);
                    $data->setFetchMode(PDO::FETCH_ASSOC);
                    foreach ($data as $row) {
                        echo " <tr> \n";
                        foreach ($row as $name => $value) {
                            echo " <td>$value</td> \n";
                        } // end field loop
                        echo " </tr> \n";
                    } // end record loop
                    echo "</table> \n";
                    echo "<input type='submit' name='changebillable_submit' value='SUBMIT'/>";
                    echo "<form>";
                } catch (PDOException $e) {
                    echo 'ERROR: ' . $e->getMessage();
                } // end try
                ?>
            </p>
                </div>
</div>

