       
        <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);
                    $query = "select DISTINCT
k.knd_name as 'Company Name',
right(p.pct_name,CHAR_LENGTH(p.pct_name) - 5 ) as 'Project Name',
left(p.pct_name,4) as 'Project Number',
p.pct_name as 'Project',
e.evt_name as 'Tasks',
e.evt_ID as 'Task ID',
CONCAT(left(p.pct_name,4), '.',e.evt_ID) as 'Main Task ID'
from kimai15_evt e
inner join kimai15_pct_evt i using (evt_ID)
inner join kimai15_pct p on i.pct_ID=p.pct_ID
inner join kimai15_knd k on p.pct_kndID=k.knd_ID
where p.pct_visible = 1
order by 
k.knd_name,
left(p.pct_name,4),
right(p.pct_name,CHAR_LENGTH(p.pct_name) - 5 ),
e.evt_name";

                    //first pass just gets the column names
                    echo '<table id="myTable" border="1" cellpadding="3" cellspacing="0" width="100%">';
                    $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";
                } catch (PDOException $e) {
                    echo 'ERROR: ' . $e->getMessage();
                } // end try
                ?>
            </p>
              </div>
</div>

