我有一个我正在做的迷你项目,并且已经成功地进行了求和和平均工作,但是在不同的数据表上。我想在一个数据表中完成这项工作。总和列号 股票和市场价格也不同..平均收益/损失列
不幸的是,我对编程知之甚少。这是代码:
**
- index.php
**
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<style>
.company-heading {
color: #fff;
background-color: #3c3d41;
padding-left: 20px;
}
.company-heading h1 {
padding-bottom: 5px;
font-size: 26px;
text-align: center;
}
.company-heading img {
height: 60px;
width: 60px;
padding: 5px 0px 5px 0px;
}
.back-link a {
color: #3c3d41;
padding-left: 4%;
}
.back-link a:hover {
color: #800000;
}
.font {
font-family: "Raleway", Helvetica, Arial, sans-serif;
}
div.dataTables_wrapper div.dataTables_processing {
background: #a9a9a9;
color: #fff;
}
.pagination > li > a, .pagination > li > span{
background-color:#515151;
color:#fff;
}
.pagination > li.active > a, .pagination > li.active > span{
background-color:#800000;
}
.pagination>.active>a,.pagination>.active>a:focus,.pagination>.active>a:hover,.pagination>.active>span,.pagination>.active>span:focus,.pagination>.active>span:hover{
z-index:3;
color:#fff;
cursor:default;
background-color:#800000;
border-color:#800000
}
.table-content tr:nth-child(odd){
background-color: #fff;
}
.table-content tr:nth-child(even){
background: #e8e5e5;
}
</style>
<div class="row company-heading">
<div class="col-sm-2 logo-print">
<a href="../home/"><img src="../assets/images/libra.png"></a>
</div>
<div class="col-sm-8">
<h1>No. of Shares Report</h1>
</div>
<div class="col-sm-2">
<h1></h1>
</div>
</div>
<br>
<div class="container box font">
<div class="table-responsive">
<table id="order_data_shares" class="table table-bordered table-striped">
<thead class="table-content">
<tr style="background-color: #800000;">
<th style="color: #fff;">Date</th>
<th style="color: #fff;">Company Name</th>
<th style="color: #fff;">No. Of Shares</th>
<th style="color: #fff;">Market Price</th>
<th style="color: #fff;">Gain / Loss</th>
</tr>
</thead>
<tbody></tbody>
<tfoot style="background-color: #800000;">
<tr>
<th colspan="2" style="color: #fff;"><strong> Total No. of Shares</strong></th></th>
<th colspan="1" id="total_order_shares" style="color: #fff;"></th></th>
<th colspan="2"></th>
</tr>
</tfoot>
</table>
<br />
<br />
<br />
</div>
</div>
<div class="row">
<div class="col-sm-12 back-link">
<a href="../home/"><i class="far fa-folder-open"></i> Dashboard</a><br><br>
</div>
</div>
<div class="footer-copyright" style="background-color: #3c3d41;height: 60px;">
</div>
</body>
</html>
<script type="text/javascript" language="javascript" >
$(document).ready(function(){
var dataTable = $('#order_data_shares').DataTable({
"processing" : true,
"serverSide" : true,
"order" : [],
"language" : {
"processing" : "Processing Search Request..."
},
"ajax" : {
url:"fetchsearchshares.php",
type:"POST"
},
drawCallback:function(settings)
{
$('#total_order_shares').html(settings.json.total);
}
});
});
</script>
**
- fetchsearchshares.php
**
<?php
//fetch.php
$connect = new PDO("mysql:host=localhost;dbname=db", "root", "pass");
$column = array('tarehe', 'doc_type', 'date', 'dateout', 'receive_by');
$query = '
SELECT * FROM transaction
WHERE tarehe LIKE "%'.$_POST["search"]["value"].'%"
OR doc_type LIKE "%'.$_POST["search"]["value"].'%"
OR date LIKE "%'.$_POST["search"]["value"].'%"
OR dateout LIKE "%'.$_POST["search"]["value"].'%"
OR receive_by LIKE "%'.$_POST["search"]["value"].'%"
';
if(isset($_POST["order"]))
{
$query .= 'ORDER BY '.$column[$_POST['order']['0']['column']].' '.$_POST['order']['0']['dir'].' ';
}
else
{
$query .= 'ORDER BY id DESC ';
}
$query1 = '';
if($_POST["length"] != -1)
{
$query1 = 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
}
$statement = $connect->prepare($query);
$statement->execute();
$number_filter_row = $statement->rowCount();
$statement = $connect->prepare($query . $query1);
$statement->execute();
$result = $statement->fetchAll();
$data = array();
$toal_order_shares = 0;
foreach($result as $row)
{
$sub_array = array();
$sub_array[] = $row["tarehe"];
$sub_array[] = $row["doc_type"];
$sub_array[] = $row["date"];
$sub_array[] = $row["dateout"];
$sub_array[] = $row["receive_by"];
$toal_order_shares = $toal_order_shares + floatval($row["date"]);
$data[] = $sub_array;
}
function count_all_data($connect)
{
$query = "SELECT * FROM transaction";
$statement = $connect->prepare($query);
$statement->execute();
return $statement->rowCount();
}
$output = array(
'draw' => intval($_POST["draw"]),
'recordsTotal' => count_all_data($connect),
'recordsFiltered' => $number_filter_row,
'data' => $data,
'total' => number_format($toal_order_shares, 2)
);
echo json_encode($output);
?>