0

I created a table from using php and added the plugin (used demo_table.css). The arrows wouldn't show on the result page and it doesn;t apply any css.

Here is my php code:

        $result = mysqli_query($link, $sql);

$num_rows = mysqli_num_rows($result);
        echo '<table cellpadding = "0" cellspacing="0" border="0" id="datatables"  class="display">';
        echo '<thead>';
        echo '<tr>';
        echo '<th>SNo.</th>
        <th>Username</th>
        <th>Trip ID</th>
        <th>Destination</th>
        <th >Leave Date</th>
        <th>Return Date</th>
        <th>Total</th>
        <th>Submit Date</th>
        <th >Status</th>
        <th >Reason</th>
        <th >Update</th>';
        echo '</tr>';
        echo '</thead>';
        echo '<tbody>';

}       else {
            echo('not valid user');
        }

if (!$result) {
    die(mysqli_error($link));

    }

if ($num_rows<=0){
    echo('not valid user');
    }

    elseif ($num_rows>0){
        $i=1;
        while($row = mysqli_fetch_assoc($result)) {

                $grandtotal = $row['flight_estimate'] + $row['registration_fee'] + $row['total_cost'];
                $status = $row['status'];
                if(($status == 'Approved') || ($status == 'Denied')){
                    $newcolumn = '<td></td>';
                }
                else{
                    $newcolumn = '<td><a href="Adminview.php?trip_id=' . $row['trip_id'] . '" id="editlink">Approve/Deny</a></td>';

                }

                echo '<tr>';
                echo '<td>'. $i++ .'</td><td>'.$row['username'].'</td><td>'.$row['trip_id'].'</td><td>'.$row['destination'].'</td><td>'.date('d/m/Y',strtotime($row['leave_date'])).'</td><td >'.date('d/m/Y',strtotime($row['return_date'])).'</td><td >'. round($grandtotal,2).'</td><td >'.date('d/m/Y',strtotime($row['updateddate'])).'</td><td >'.$row['status'].'</td><td >'.$row['reason'].'</td>'.$newcolumn;
            }
    echo '</tr>';
    echo '</tbody>';
    echo '</table>';

} ?>

Is there anything that I'm missing? All it does is center all the column values. But when I click on header nothing happens.

slifkax
  • 3
  • 4
  • http://stackoverflow.com/questions/14098680/dynamically-get-column-names-in-acolumns-arrary-in-datatables – Vaibs_Cool Aug 09 '13 at 18:14
  • I would start by cleaning a little all this condicionals, you probably don't need them all. Now, elseif has space, you wrote it without. else if (). – madagalbiati Aug 09 '13 at 18:15
  • where do you initialize the datatable? – davidkonrad Aug 11 '13 at 09:22
  • @davidkonrad I have a separate script file in my main page..here is the part of it: $(document).ready(function() { $("#datatables").dataTable(); }); – slifkax Aug 14 '13 at 17:26

1 Answers1

0

You need to set 'bJQueryUI' to true when you init dataTable

$("#datatables").dataTable({ 'bJQueryUI' : true });

It would help if you posted your js script as that is where your problem is.

Binary Alchemist
  • 1,600
  • 1
  • 13
  • 28