Quantcast
Viewing all articles
Browse latest Browse all 82127

DataTables not working

index.html
        <div class="span12" id="result"></div>

        <div class="span12" id="examples">
          <table class="table" id="example">
            <thead><tr>
              <th>id</th>
              <th>date</th>
              <th>location</th>
            </tr></thead>
            <tbody>
              <tr>
                <td>1</td>
                <td>05/01/2013</td>
                <td>SF</td>
              </tr>
              <tr>
                <td>2</td>
                <td>05/01/2013</td>
                <td>SF</td>
              </tr>
              <tr>
                <td>3</td>
                <td>05/01/2013</td>
                <td>SF</td>
              </tr>
              <tr>
                <td>4</td>
                <td>05/01/2013</td>
                <td>SF</td>
              </tr>
              <tr>
                <td>5</td>
                <td>05/01/2013</td>
                <td>SF</td>
              </tr>              
            </tbody>
          </table>
        </div>

    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="DataTables/media/js/jquery.dataTables.js"></script>

    <script type="text/javascript">

    window.onload = function(){
      $.post('sql.php', function (output) {
        $('#result').html(output).show();     
      }).fail(function () { console.log('fail')});
    };
    
    $(document).ready(function(){
      $('#result_table').dataTable();
    });

    $(document).ready(function(){
      $('#example').dataTable();
    });
    </script>

sql.php
<?php 
$connection = SQL_connection;
$row = some sql query;
writeTable($row);

function writeTable($row){ ?>

<table class='table table-bordered table-striped' id="results_table">
    <thead>
        <tr>
            <th>ID</th>
            <th>Date</th>
            <th>Location</th>
            <th>Status</th>
            <th>Summary</th>
        </tr>
    </thead>
    <tbody>
        <tr>
    
<?php
    foreach ($row as $row) { ?>
            <td><?= $row['id'] ?></td>
            <td><?= $row['date'] ?></td>
            <td><?= $row['location'] ?></td>
            <td><?= $row['status'] ?></td>
            <td><?= $row['summary'] ?>"></td>
        </tr>
<?php   } ?>
    </tbody>
</table> 


<?php }

#result is an empty div where I want to show the result_table after running a mysql query (done in sql.php). however, result_table is not converted to a DataTable. the #example table is a table I created in my html to test if DataTable is working, and it is. can someone help me please?

Viewing all articles
Browse latest Browse all 82127

Trending Articles