-2
私はPHPの初心者です。私は自分のDBとの簡単な接続を書いて、そこからいくつかのレコードを取り出して単純なテーブルに表示しました。今私は効率的な方法でデータを表示するためにjQuery Datatablesを使用したいと思います。私はbootstrap, jQuery and jQuery Datatables plugin
をダウンロードしました。ベローは私が含まれているjQuery datatableをPHPで使用する
<script src="Scripts/jquery-3.1.1.js"></script>
<script src="Scripts/DataTables/jquery.dataTables.js"></script>
<link href="Content/bootstrap.css" rel="stylesheet" />
<link href="Content/DataTables/css/dataTables.bootstrap.css" rel="stylesheet" />
これは私のPHPコードです:
<?php
require_once('config.php');
$sql = "SELECT Device_ID, Energy_kwh, Power_kW, Voltage_Phase_1,Voltage_Phase_2,Voltage_Phase_3, Current_Phase_1,Current_Phase_2,Current_Phase_3, Data_Datetime, Device_Serial_Number FROM ads_device_data where Device_ID= '2'";
//$result = $con->query($sql);
if($result = mysqli_query($con,$sql))
{
if(mysqli_num_rows($result)>0)
{
echo"<table id='myTable'>";
echo"<tr>";
echo"<th>ID</th>";
echo"<th>Energy</th>";
echo"<th>Power</th>";
echo"<th>Voltage (all phases)</th>";
echo"<th>Current (all phases)</th>";
echo"<th>Date Time</th>";
echo"<th>Serial #</th>";
echo"</tr>";
while($row = mysqli_fetch_array($result))
{
echo"<tr style='text-align:center'>";
echo"<td>" . $row['Device_ID'] . "</td>";
echo"<td>" . $row['Energy_kwh'] . "</td>";
echo"<td>" . $row['Power_kW'] . "</td>";
echo"<td>" . $row['Voltage_Phase_1'] . " : " . $row['Voltage_Phase_2'] . " : " . $row['Voltage_Phase_3'] . "</td>";
echo"<td>" . $row['Current_Phase_1'] . " : " . $row['Current_Phase_2'] . " : " . $row['Current_Phase_3'] . "</td>";
echo"<td>" . $row['Data_Datetime'] . "</td>";
echo"<td>" . $row['Device_Serial_Number'] . "</td>";
echo"</tr>";
//echo "id: ".$row["Device_ID"]." <br> "." -Energy ".$row["Energy_kwh"]." <br> "." -Power " .$row["Power_kW"]." <br> "." -Voltage(all phases) ".$row["Voltage_Phase_1"]. " " .$row["Voltage_Phase_2"]. " " .$row["Voltage_Phase_3"]." <br> ". "-Current(all phases)" .$row["Current_Phase_1"]. " " .$row["Current_Phase_2"]. " " .$row["Current_Phase_3"]." <br> ". " -Date Time " .$row["Data_Datetime"]." <br> "." Serial# ".$row["Device_Serial_Number"]. " <br> ";
}
echo"</table>";
mysqli_free_result($result);
}
else
{
echo "No records matching your query were found.";
}
}else
{
//$result->close();
//mysqli_free_result($result);
echo "ERROR: Could not able to execute the query. " . mysqli_error($con);
}
mysqli_close($con);
//$con->close();
?>
親切にそれを行う方法を私を助けて?
<script>
$(document).ready(function() {
$('#myTable').DataTable();
});
<script>
それを行う必要があります。
は、すべてのヘルプは非常に
あなたはベンダーのWebサイト上の例のいずれかを見ていましたか? https://www.datatables.net – David