2016-10-19 5 views
0

私はmysqlクエリを実行するコントローラページが1つあるサイトです。結果はm_analitica.phpという名前のビューアページに出力され、上部にはinclude("header.php")、下部にはinclude("footer")と表示されます。 footer.phpでbody要素の閉鎖前に、次にBootstrap dataTableはPHPテーブルでソートして検索していません

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
<link rel="stylesheet" href="../public/js/DataTables-1.10.12/media/css/dataTables.bootstrap.min.css" /> 
<link href="../public/css/bootstrap.min.css" rel="stylesheet"/> 
<script src="../public/js/bootstrap.min.js"></script> 
<script src="../public/js/DataTables-1.10.12/media/js/jquery.dataTables.min.js"></script> 
<script src="../public/js/DataTables-1.10.12/media/js/dataTables.bootstrap.min.js"></script> 

私は:

m_analitica.phpのためのコード:私は以下のjsスクリプトやCSSを含まheader.phpヘッド

<div> 
<table class="table table-striped table-bordered table-hover" id="myTable"> 
    <div><h2>Mapa Analítica</h2></div> 
    <thead> 
     <tr> 
      <th>Name</th> 
      <th>Tipo Documento</th> 
      <th>Número</th> 
      <th>Cliente</th> 
      <th>Obra</th> 
      <th>Designação</th> 
      <th>Agregado</th> 
      <th>Quantidade (ton)</th> 
     </tr> 
    </thead> 
    <tfoot> 
     <tr> 
      <th>Name</th> 
      <th>Tipo Documento</th> 
      <th>Número</th> 
      <th>Cliente</th> 
      <th>Obra</th> 
      <th>Designação</th> 
      <th>Agregado</th> 
      <th>Quantidade (ton)</th> 
     </tr> 
    </tfoot> 


    <?php foreach ($positions as $position): ?> 
     <tbody> 
      <tr> 
       <td><?= $position["data"] ?></td> 
       <td><?= $position["tipo"] ?></td> 
       <td><?= $position["num"] ?></td> 
       <td><?= $position["cliente"] ?></td> 
       <td><?= $position["obra"] ?></td> 
       <td><?= $position["nome_obra"] ?></td> 
       <td><?= $position["agr"] ?></td> 
       <td><?= $position["ton"] ?></td> 
      </tr> 
     </tbody> 
    <?php endforeach ?> 
</table> 

スクリプトを挿入しました:

<script type="text/javascript"> 
    $('#myTable').dataTable(); 
</script> 

テーブルをページに分割せず、検索と並べ替えが機能しない場合は、クリックするだけで何もしません。

ブートストラップdataTableはphpで動作しませんか?またはforeachループで?またはコードに何か問題があります。

+0

https://datatables.net/examples/data_sources/server_side.htmlそれに従ってください。 –

+0

私は以前にそれを試しました。 –

答えて

1

ループ内から<tbody>タグを削除します。 <tr>タグだけを繰り返してください。 <tbody>タグをループの外側に配置します。

+0

それは働いてくれてありがとう、あなたの過去2日間保存! –

+0

これは簡単な修正だとうれしいです。 – LStarky

関連する問題