I want the result of my jquery to show in the table i have in another file.
I've tried changing the id of the table but my table is from bootstrap so
the css changes if I change the id. I don't know what else to do.
These are my files
config.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$db = "stock-stock-stock";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $db );
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
?>
read_students.php
include_once('../config.php');
$sql = "SELECT * FROM games WHERE status='available'";
$query = $conn->query($sql);
$result = array("data" => array());
while($data = $query->fetch_assoc()){
$checkbox = '<input type="checkbox" class="checkbox" id="checkbox_' . $data['id'] . '"
value="' . $data['id'] . '" name="groupCheckBox" onchange="enableDeleteAllButton(this)">';
$image = '<img width="100" height="100" class="" src="' . $data['game_pic'] . '">';
$buttons = '<a href="game-update.php?$id='. $data['id'] . '" class="btn btn-info btn-sm">
<i class="fa fa-edit" aria-hidden="true"></i></a><a onclick="removeGame(' . $data['id'] . ')" class="btn btn-danger btn-sm"><i class="fa fa-trash" aria-hidden="true"></i></a>';
// need "data" string
$result["data"][] = array(
$checkbox,
$data['id'],
$data['game_name'],
$data['players'],
$data['game_descrip'],
$image,
$data['status'],
$buttons,
);
}
echo json_encode($result);
?>
this is my table where I want the result to be displayed in.
list_students.php
<table class="table table-bordered" id="myTables" width="100%" cellspacing="0">
<thead>
<tr align="center">
<th></th>
<th>Game ID</th>
<th>Game Name</th>
<th>Category</th>
<th>Description</th>
<th>Photo</th>
<th>Availability</th>
<th>Action</th>
</tr>
</thead>
<tbody>
</tbody>
</div>
</div>
<tbody>
</tbody>
</table>
this is my script in the same file as my table
$(document).ready(function() {
var gameTable = $("#myTables").DataTable({
"ajax": "jquery/read_students.php",
"order": [1, 'desc'],
"aoColumnDefs": [{
"bSortable": false,
"aTargets": [ 0,1,2,3,4,5,6],
},{
"targets": [1],
"visible": false,
"searchable": true,
}]
});
});