no data available in table but data from the database is displayed - javascript

The data table displays the the contents of the database but still shows an error message: no data available in table.
how do i fix this, just show the data without the error message
<table name= "displaycase" id="example1" class="table table-bordered table-striped" method = "post">
<thead>
<tr>
<th>Case Title</th>
<th>Court</th>
<th>Dockent Number</th>
<th>Nature</th>
<th>Actions Taken</th>
<th>Status</th>
<th>Due Date </th>
</tr>
</thead>
<tbody>
<tbody class = "searchable">
<?php
if (mysql_num_rows($result) > 0) {
// output data of each row
while ($row = mysql_fetch_assoc($result)) {
echo
"</td><td>" . $row["CaseTitle"] .
"</td><td>" . $row["Court"] .
"</td><td>" . $row["docketNum"] .
"</td><td>" . $row["nature"] .
"</td><td>" . $row["actionsTaken"] .
"</td> <td>" . $row["status"] .
"</td> <td>" . $row["dueDate"] .
"</td></tr>";
}
} else {
}
?>
</tbody>
-
<script>
$( document ).ready(function() {
$("#example1").DataTable({
"paging": false,
"ordering": true,
"info": false,
"language": {
"emptyTable": "No Data"
}
})
});</script>

Remove method = "post" from <table> tag.
Why Two <tbody> tag present inside <table>. Remove One.
Why </td> is closed when it didn't opened yet.
No <tr> opened.
UPDATE CODE:
<table name= "displaycase" id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>Case Title</th>
<th>Court</th>
<th>Dockent Number</th>
<th>Nature</th>
<th>Actions Taken</th>
<th>Status</th>
<th>Due Date </th>
</tr>
</thead>
<tbody class = "searchable">
<?php
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
echo
"<tr>".
"<td>" . $row["CaseTitle"] ."</td>".
"<td>" . $row["Court"] ."</td>".
"<td>" . $row["docketNum"] ."</td>".
"<td>" . $row["nature"] ."</td>".
"<td>" . $row["actionsTaken"] ."</td>".
"<td>" . $row["status"] ."</td>".
"<td>" . $row["dueDate"] ."</td>".
"</tr>";
}
} else {
}
?>
</tbody>
</table>
[NOTE: The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

That's because you missed a tr and instead you echo </td> in the echo here
while($row = mysql_fetch_assoc($result)) {
echo
"<tr><td>".$row["CaseTitle"].
"</td><td>".$row["Court"].
"</td><td>".$row["docketNum"].
"</td><td>".$row["nature"].
"</td><td>".$row["actionsTaken"].
"</td> <td>".$row["status"].
"</td> <td>".$row["dueDate"].
"</td></tr>";
}

Related

Hidding A button with JQuery with Conditions

I have a table called report
and currently im trying to read what is the value in the status column in order to hide or display the retryBtn depending on the value in it.
I have also included the JQuery script by manually copy pasting the code & saving in into a file.
Right now I have wrote a JQuery code that runs on load, but it seems like it wasnt run at all as the log shows nothing. What is the reason that its not running, in the src folder the website is able to detect the JQuery.js script.
Any advice?
Table
<div class="table" id="table_report">
<table class="report" id="report">
<tr>
<th class="column">ID</th>
<th class="column">A</th>
<th class="column">B</th>
<th class="column">Status</th>
<th class="column"> C </th>
<th class="column">D Path</th>
<th class="column"> E</th>
<th class="column">E Path</th>
<th class="column"> F</th>
<th class="column">F Path</th>
<th class="column">G </th>
<th class="column">G Path</th>
<th class="column"> </th>
</tr>
while($row = $statement->fetch(PDO::FETCH_ASSOC)){
$fullPSPath = $G_Path . $row['GPath'];
$fullEPath = $E_Path . $row['EPath'];
$fullDPath = $D_Path . $row['DPath'];
$fullFPath = $F_Path . $row['FPath'];
echo "<tr>"
. "<td>". $row['ID']."</td><td>"
. $row['A']."</td><td>" .$row['B']. "</td><td><span class='status'>". $row['Status'] . "</span></td><td>"
. $row['D']. "</td><td>" . "<a href='download.php?type=D&path=". $fullDPath. "'> $fullDPath</a></td><td>"
. $row['E']. "</td><td>". "<a href='download.php?type=E&path=". $fullEPath. "'> $fullEPath</a></td><td>"
. $row['F']. "</td><td>"
. "<a href='download.php?type=F&path=". $fullFPath. "'> $fullFPath</a></td><td>"
. $row['G']. "</td><td>"
. "<a href='download.php?type=G&path=". $fullGPath . "'> $fullGPath </a></td>"
. "<td><button class='Retry' id='retryBtn'>Retry</button></td>";//button here
echo '</tr>';
}
?>
JQuery
<script type="text/javascript">
'use strict';
$(document).ready(function(){//code not run at all.
$("#report").load(function(){
console.log('here');
var retryBtn = document.getElementById('retry');
//retryBtn.style.visibility = "hidden";
var currentRow = $(this).closest("tr");
var status = currentRow.find(".status");
if(status == "Failed")
{
retryBtn.style.display = "block";
}else{
retryBtn.style.display = "none";
};
});
});
</script>

Refreshing DataTables table populated with loop

I want to update table content without refreshing the page but I fill the table using a loop on the same page. Here is the code I use:
<div id="items_table">
<div class="table-responsive" id="table_allitems">
<table id="products_all" class="table-sm table-bordered table-hover" style="width: 100%;">
<thead class="table-secondary table-hover">
<tr>
<th scope="col">
<center>Код</center>
</th>
<th scope="col">
<center>Име</center>
</th>
<th scope="col">
<center>Баркод</center>
</th>
<th scope="col">
<center>Група</center>
</th>
<th scope="col">
<center>Мярка</center>
</th>
<th scope="col">
<center>Количество</center>
</th>
<th scope="col">
<center>Обект</center>
</th>
<th scope="col">
<center>Доставна цена</center>
</th>
<th scope="col">
<center>Продажна цена</center>
</th>
<th scope="col"></th>
</tr>
</thead>
<tbody id="skladove_table">
<?php
$query_checkObekt = "SELECT * FROM obekti WHERE owner='$user_hash'";
$result_checkObekt = mysqli_query($conn, $query_checkObekt);
if(mysqli_num_rows($result_checkObekt) > 0) {
$query = "SELECT * FROM items WHERE owner ='$user_hash'";
$result=mysqli_query($conn, $query);
while($row = mysqli_fetch_assoc($result))
{
echo '<tr id="' . $row['unique_id'] . '" onmouseover=showItem(' . $row['unique_id'] . ');>';
echo "<td>" . "<center>" . $row['custom_id'] . "</center>" . "</td>";
echo "<td>" . "<center>" . $row['name'] . "</center>" . "</td>";
echo "<td>" . "<center>" . $row['barcode'] . "</center>" . "</td>";
echo "<td>" . "<center>" . $row['grupa'] . "</center>" . "</td>";
echo "<td>" . "<center>" . $row['quantity_type'] . "</center>" . "</td>";
echo "<td>" . "<center>" . $row['quantity_number'] . "</center>" . "</td>";
echo "<td>" . "<center>" . $row['obekt'] . "</center>" . "</td>";
echo "<td>" . "<center>" . $row['price_delivery'] . "</center>" . "</td>";
echo "<td>" . "<center>" . $row['price_sale'] . "</center>" . "</td>";
echo "<td style='width: 1%; padding-left: 1%; padding-right: 1%;' onclick='deleteItem(" . $row['unique_id'] . ");'><i class='fa fa-close'></i>"."</td>";
echo "</tr>";
}
} else {
//no records found
}
?>
</tbody>
</table>
</div><br
To add new item I use iframe modal and what I want is after closing the modal or just pressing one button table to get refreshed (and if possible to stay on the same page) with the new info without refreshing the page.

DataTables Expand Row to Show Additional Details

I have a DataTables on a page and want to be able to click anywhere on that row to expand it and show some additional information the docs. However I do not set up my table in JS/Ajax, it's just an HTML table loaded with dynamic information from PHP.
Here is my table:
Here is the the table code:
<table id="tickets" class="table table-striped">
<thead>
<tr>
<th>Ticket #</th>
<th>Agent</th>
<th>Ext.</th>
<th>Ticket Date</th>
<th>Subject</th>
<!-- <th>Text</th> -->
<th>Status</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php
if (pg_num_rows($ticketsQuery) > 0) {
foreach ($ticketsList as $value) {
echo "<tr>";
echo "<td class='col-xs-1'>" . $value['incident_number'] . "</td>";
echo "<td class='col-xs-2'>" . $value['agent'];
if ($value['additional_agent_1'] != '') {
echo "<br>" . $value['additional_agent_1'];
}
if ($value['additional_agent_2'] != '') {
echo "<br>" . $value['additional_agent_2'];
}
if ($value['additional_agent_3'] != '') {
echo "<br>" . $value['additional_agent_3'];
}
echo "</td>";
if ($value['agent_extension'] != '' && $value['agent_extension'] != null) {
echo "<td class='col-xs-1'>ext. " . $value['agent_extension'] . "</td>";
} else {
echo "<td class='col-xs-1'></td>";
}
echo "<td class='col-xs-2'>" . date("D, M. j, Y", strtotime($value['incident_opening_date'])) . "</td>";
echo "<td class='col-xs-3'>" . $value['incident_subject'] . "</td>";
echo "<td class='col-xs-2'>" . $value['incident_status'] . "</td>";
echo "<td class='col-xs-1 text-center'>";
echo "<form action='edit_tickets.php' method='post' style='display:inline-block;'>";
echo "<button class='btn btn-info btn-xs' id='btnEditTicket' name='btnEditTicket' value='" . $value['incident_number'] . "'>Edit</button>";
echo "</form>";
echo "</td>";
echo "</tr>";
}
unset($value); // Unset the foreach value
}
?>
</tbody>
</table>
Here is my DataTable init:
<script>
$(document).ready(function() {
$('#tickets').DataTable({
dom: "<'row'<'col-xs-12 col-sm-6 col-sm-push-2'B><'col-xs-6 col-sm-2 col-sm-pull-6'l><'col-xs-6 col-sm-4'f>>" +
"<'row'<'col-xs-6'><'col-xs-6'>>" +
"<'row'<'col-xs-12't>>" +
"<'row'<'col-xs-12 col-sm-4'i><'col-xs-12 col-sm-8'p>>",
buttons: [
'copy',
'csv',
'excel',
'pdf',
{
extend: 'print'
}
],
columnDefs: [ {
targets: [ 0 ],
orderData: [ 0, 1 ]
}, {
targets: [ 1 ],
orderData: [ 1, 0 ]
} ],
"order": [[3, "desc" ]]
});
});
</script>
Here is the end goal:

PHP, how to get datepicker value from database if date != current date

I spend more than two days with no luck, when open site, its display all orders for current date. But sometimes I need to add order in previous date, after inserting, query return me to the index page and again its display the orders today, but i want now to display the last record which have different date.
code in index page:
<script>
$('#datepicker').change(function () {
$.post('check_data.php', {
dtpickerdate : $(this).val()
}, function (response) {
$('table').html(response);
});
});
$("#datepicker").datepicker({dateFormat: "mm-dd-yy",}).datepicker("setDate", new Date()).change();
</script>
insert query:
$conn->query("INSERT INTO `orders` VALUES('$order_no','$address','$no_ofppl','$d_time','$k_time','$date',now(),'$done','$mile')") or die('Error: ' . mysqli_error($conn));
echo '
<script type = "text/javascript">
alert("Saved Record");
window.location = "index.php";
</script>
'; }
}else
{
echo 'Result Error';
}
Check_data.php
<thead class = "alert-info">
<tr>
<th>Kitchen Time</th>
<th>Order#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Address</th>
<th>Driver#</th>
<th>Delivery Time</th>
<th># of People</th>
<th>Miles</th>
</tr> </thead><tbody>
<?php
$dtpickerdate = isset($_POST['dtpickerdate']) ? $_POST['dtpickerdate'] : NULL;
$q_customer = $conn->query
("SELECT * from orders inner JOIN customer_order on customer_order.order_no =orders.order_no and orders.date like'$dtpickerdate' inner join driver_order on driver_order.order_no=orders.order_no LEFT JOIN customer on customer.phone=customer_order.phone order by k_time,time desc" )
or die(mysqli_error());
$k_time = '';
while($f_customer = $q_customer->fetch_array()){
$s=mysqli_num_rows($q_customer);
?>
<tr>
<?php
if($k_time == '' || $k_time != $f_customer['k_time']){
$k_time = $f_customer['k_time'];
echo '<td align="center" > <span style=" font-weight:bold;">'
.$f_customer['k_time']. '</td>';
} else{
echo "<td td style=' border: none;'> </td>";
}
echo "<td style='background-color: #5f5d5d; ' align='center' span style='font-weight:bold;'> <a href = '#' style='color:#ececec;font-weight:bold;' data-toggle = 'modal' data-target = '#action'>".$f_customer['order_no']."</a></td>";
echo "<td style='background-color: #5f5d5d;color:#ececec;'>" .$f_customer['first_name']."</td>";
echo "<td style='background-color: #5f5d5d;color:#ececec;'>". $f_customer['last_name']."</td>";
echo "<td style='background-color: #5f5d5d;color:#ececec;'>". $f_customer['address']."</td>";
echo "<td style='background-color: #5f5d5d;color:#ececec;'>". $f_customer['driver_no']."</td>";
echo "<td style='background-color: #5f5d5d;color:#ececec;'>". $f_customer['d_time']."</td>";
echo "<td style='background-color: #5f5d5d;color:#ececec;'>". $f_customer['no_ofppl']."</td>";
}

How to show all records using PHP function and Javascript

I am new to mvc and I want to populate my table from database and I am having trouble with showing the data with the use of javascript to show it on my index. I am using a php function to query the sql script and i am using PDO.
index.php
<tr>
<th>last_name</th>
<th>first_name</th>
<th>middle_name</th>
<th>gender</th>
<th>age</th>
<th>course</th>
</tr>
<tr>
<div id=content> </div
</tr>
profile.php
public function showProfileRecord(){
require_once 'app/lib/config/config.php';
$result = $conn->prepare("SELECT a.`first_name`, a.`middle_name`, a.`last_name`,a.`gender`,a.`age`, a.`course` FROM account a ORDER BY name ASC");
while ($rows = $result->fetch()) {
$records = $records . "<td>" . $rows["last_name"] . "</td> <td>" . $rows["first_name"] . "</td> <td>" . $rows["middle_name"] . "</td> <td>" . $rows["gender"] . "</td> <td>". $rows["age"] . "</td> <td>" . $rows["course"] . "</td>";
}
$returnData[]["records"] = $records;
echo json_encode($returnData);
}
functions.js
showProfileRecord = function(data){
data = JSON.parse(data);
$("#content").append("\
<tr>" + data[0].records + "</tr>\
");
}

Categories