2017-03-30 15:00



I have tried to add datatables to my PHP web apps table. I have followed the instructions and add a thead and tbody tag, also the link at the top and the document.ready in the script tags at the bottom. Nothing seems to be working. any ideas?



    <link rel="stylesheet" type="text/css" href="css/style.css"> 
    <script src=""></script>
    <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
    <script src=""></script>
    <script type="text/javascript" charset="utf8" src="//"></script>

<title>View Records</title>


    <div class="page-wrap">
    <center><a href=""><img src="/images/logo.png" alt="what image shows" height="90" width="300"></a></center>
    <h1>GCS Reproduction Environment</h1></br>

    <h2>All Reproductions</h2>




Displays all data from 'players' table


// connect to the database


// ordering the ID function

$ascdesc = "";
$order = isset($_GET['sort'])?$_GET['sort']:'id';

$ascdesc = isset($_GET['ascdesc'])?$_GET['ascdesc']:'DESC';
  case 'DESC': $ascdesc = 'ASC'; break;
  case 'ASC': $ascdesc = 'DESC'; break;
  default: $ascdesc = 'DESC'; break;

// get results from database

$result = mysql_query("SELECT * FROM players ORDER BY $order $ascdesc")

or die(mysql_error());

// display data in table

echo "<table id='#myTable' align='center' border='1' cellpadding='2'>";
echo "<thead> <tr> <th>ID</th> <th>Administration Console</th> <th>Product Version</th> <th>Platform</th> <th>Database</th> <th>Owner</th> <th>Status</th> <th></th> <th></th></tr> </thead>";

// loop through results of database query, displaying them in the table

while($row = mysql_fetch_array( $result )) {

// echo out the contents of each row into a table
echo "<tbody>";

echo "<tr>";

echo '<th>' . $row['id'] . '</th>';

echo '<td><a href="'.$row['curl'].'">'.$row['curl'].'</a></td>';

echo '<td>' . $row['pversion'] . '</td>';

echo '<td>' . $row['platform'] . '</td>';

echo '<td>' . $row['dversion'] . '</td>';

echo '<td><a href="mailto:'.$row['email'].'">' . $row['email'].'</a></td>';

echo '<td>' . $row['status'] .'</td>';

echo '<td><a href="php/edit.php?id=' . $row['id'] . '">Edit</a></td>';

echo '<td><a onclick="javascript:confirmationDelete($(this));return false;" href="php/delete.php?id=' . $row['id'] . '"onclick="return confirm("Do you want to delete this?")">Delete</a></td>';

echo "</tr>";

echo "</tbody>";


// close table>

echo "</table>";


    function confirmationDelete(anchor)
   var conf = confirm('Are you sure want to delete this record?');

  function () {
  function () {



<p><a href="php/new.php">Add a new record</a></p>



  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dourukeng5302 dourukeng5302 4年前

    You don't have to use # to specify ID. Change the following echo "<table id='#myTable' align='center' border='1' cellpadding='2'>";
    to echo "<table id='myTable' align='center' border='1' cellpadding='2'>";

    Also, you are including multiple versions of jQuery. You may only include <script src=""></script> Note that the original mysql extension is deprecated. (

    点赞 评论 复制链接分享
  • duancongjue9202 duancongjue9202 4年前

    Your biggest issue here is you're not calling your database in your query. It should be mysqli_query($db, "SELECT * FROM players ORDER BY $order $ascdesc") where $db is your mysqli_connect variable called in your connect-db.php file. Also your mysqli_error() should be mysqli_error($db) or whatever you called your mysqli_connect. On doing that, the mysqli_error will give you a better idea of where you're failing. You can also check your php log file to catch errors there.

    点赞 评论 复制链接分享