I think there is a simple way to align these table cells with the header from another table.
I tried to set the width of every table cell to 6%, this this doesn't align them completely.
This is my table:
https://imgur.com/a/sKUcY
This is how I create the table:
<table class="table table-striped table-bordered turnover_list">
<thead>
<tr class="sorting_1">
<th>Company</th>
<th>Year</th>
<?php
if($_POST['selectall'] == 0) {
$allCompanies = array();
$allCompanies[0] = getCompanyName($_POST['company']);
$allCompanies[1] = getCompanyName($_POST['compare']);
}
if($_POST['frommonth'] != "" && $_POST['tomonth'] != "" && $_POST['fromyear'] != "" && $_POST['toyear'] != "") {
$fromMonth = $_POST['frommonth'];
$toMonth = $_POST['tomonth'];
$fromYear = $_POST['fromyear'];
$toYear = $_POST['toyear'];
} else {
$fromMonth = 0;
$toMonth = 11;
$fromYear = date('Y');
$toYear = date('Y');
}
for($i=$fromMonth; $i<=$toMonth; $i++) {
echo "<th>" . $months[$i] . "</th>";
array_push($selectedMonths, $months[$i]);
}
for($i=$fromYear; $i<=$toYear; $i++) {
array_push($selectedYears, $i);
}
?>
<th>Total</th>
</tr>
</thead>
<?php
foreach($selectedYears as $year) {
$turnoverTotal = 0;
echo "<table class='table table-striped table-bordered turnover_list'>";
echo "<tbody>";
$monthTotal = array("January"=>"0", "February"=>"0", "March"=>"0", "April"=>"0", "May"=>"0", "June"=>"0", "July"=>"0", "August"=>"0", "September"=>"0", "October"=>"0", "November"=>"0", "December"=>"0");
foreach ($allCompanies as $companyName) {
$companyTurnoverTotal = 0;
echo "<tr>";
echo "<td style=''>" . $companyName . "</td>";
echo "<td style=''>" . $year . "</td>";
foreach ($selectedMonths as $month) {
$sql = "SELECT SUM(mob + www) AS 'turnover' FROM turnover WHERE year = '" . $year . "' AND companyID = '" . getCompanyID($companyName) . "' AND month = '" . $month . "'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$companyTurnoverMonth = $row['turnover'];
$monthTotal[$month] += $companyTurnoverMonth;
$companyTurnoverTotal += $companyTurnoverMonth;
echo "<td style=''>" . make_format($companyTurnoverMonth) . "</td>";
}
$turnoverTotal += $companyTurnoverTotal;
echo "<td style=' font-weight: bold; background-color:#d3d3d3;'>" . make_format($companyTurnoverTotal) . "</td>";
echo "</tr>";
}
echo "<tr style='font-weight: bold;'>";
echo "<td style='background-color:#d3d3d3;'>Total</td>";
echo "<td style='background-color:#d3d3d3;'>" . $year . "</td>";
foreach($selectedMonths as $month) {
echo "<td style='background-color:#d3d3d3;'>" . make_format($monthTotal[$month]) . "</td>";
}
echo "<td style='background-color:#d3d3d3;'>" . make_format($turnoverTotal) . "</td>";
echo "</tr>";
echo "</tbody>";
echo "</table>";
}
?>
</table>
I created a separate table header, because the user is able to compare companies.
Is there a way to create a table header with multiple other tables (without header) underneath it and have it all aligned with the table header?
This would be my desired result:
https://imgur.com/ZFzZluK
Related
I'm not sure my question is right.
I have made a html table and filled it with test data from the database.
Image from the table: https://imgur.com/a/UVH1e
This is my table:
<table class="table table-striped table-bordered turnover_list">
<thead>
<tr class="sorting_1">
<th>Company</th>
<th>Year</th>
<th>January</th>
<th>February</th>
<th>March</th>
<th>April</th>
<th>May</th>
<th>June</th>
<th>July</th>
<th>August</th>
<th>September</th>
<th>October</th>
<th>November</th>
<th>December</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<?php
$currentYear = date('Y');
$check = "SELECT * FROM turnover WHERE year = '" . $currentYear . "'";
$result = mysql_query($check) or die(mysql_error());
foreach ($allCompanies as $companyName) {
$companyTurnoverTotal = 0;
$turnoverTotal = 0;
echo "<tr>";
echo "<td style='width:7%;'>" . $companyName . "</td>";
echo "<td style='width:7%;'>" . $currentYear . "</td>";
$monthTotal = array("January"=>"0", "February"=>"0", "March"=>"0", "April"=>"0", "May"=>"0", "June"=>"0", "July"=>"0", "August"=>"0", "September"=>"0", "October"=>"0", "November"=>"0", "December"=>"0");
foreach ($months as $month) {
$sql = "SELECT SUM(mob + www) AS 'turnover' FROM turnover WHERE year = '" . $currentYear . "' AND companyID = '" . getCompanyID($companyName) . "' AND month = '" . $month . "'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$companyTurnoverMonth = $row['turnover'];
$monthTotal[$month] += $companyTurnoverMonth;
echo "<script>alert('" . $month . ": " . $monthTotal[$month] . "')</script>";
$companyTurnoverTotal += $companyTurnoverMonth;
$turnoverTotal += $companyTurnoverTotal;
echo "<td style='width:7%;'>" . make_format($companyTurnoverMonth) . "</td>";
}
echo "<td style='width:7%; font-weight: bold; background-color:#d3d3d3;'>" . make_format($companyTurnoverTotal) . "</td>";
echo "</tr>";
}
echo "<tr style='font-weight: bold; background-color:#d3d3d3;'>";
echo "<td style='width:7%;'>" . "Total" . "</td>";
echo "<td style='width:7%;'>" . $currentYear . "</td>";
echo "<td style='width:7%;'>" . make_format($monthTotal['January']) . "</td>";
echo "<td style='width:7%;'>" . make_format($monthTotal['February']) . "</td>";
echo "<td style='width:7%;'>" . make_format($monthTotal['March']) . "</td>";
echo "<td style='width:7%;'>" . make_format($monthTotal['April']) . "</td>";
echo "<td style='width:7%;'>" . make_format($monthTotal['May']) . "</td>";
echo "<td style='width:7%;'>" . make_format($monthTotal['June']) . "</td>";
echo "<td style='width:7%;'>" . make_format($monthTotal['July']) . "</td>";
echo "<td style='width:7%;'>" . make_format($monthTotal['August']) . "</td>";
echo "<td style='width:7%;'>" . make_format($monthTotal['September']) . "</td>";
echo "<td style='width:7%;'>" . make_format($monthTotal['October']) . "</td>";
echo "<td style='width:7%;'>" . make_format($monthTotal['November']) . "</td>";
echo "<td style='width:7%;'>" . make_format($monthTotal['December']) . "</td>";
echo "<td style='width:7%;'>" . make_format($turnoverTotal) . "</td>";
echo "</tr>";
?>
</tbody>
I want a table column at the right that shows the total of every company.
At the bottom of the table I want a row with columns per month that shows the total of every month.
I was trying to make an array with all the months and increase the value with the next column in the same month. $monthTotal[$month] += $companyTurnoverMonth;
foreach ($months as $month) {
$sql = "SELECT SUM(mob + www) AS 'turnover' FROM turnover WHERE year = '" . $currentYear . "' AND companyID = '" . getCompanyID($companyName) . "' AND month = '" . $month . "'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$companyTurnoverMonth = $row['turnover'];
$monthTotal[$month] += $companyTurnoverMonth;
$companyTurnoverTotal += $companyTurnoverMonth;
$turnoverTotal += $companyTurnoverTotal;
echo "<td style='width:7%;'>" . make_format($companyTurnoverMonth) . "</td>";
}
so i have a problem that it only shows the "personen" the second sql table.
and the first too but has no data in it.
<table border="1" class="table">
<tr>
<th class="tabl">Id</th>
<th class="tabl">Naam</th>
<th class="tabl">Adres</th>
<th class="tabl">Telefoonnummer</th>
<th class="tabl">Email</th>
<th class="tabl">Linkedin</th>
<th class="tabl">Facebook</th>
<th class="tabl">Twitter</th>
<th class="tabl">Eigen website</th>
<th class="tabl">Branchering</th>
<th class="tabl">Personen</th>
<th class="tabl">links</th>
<th class="tabl">opdrachten</th>
<th class="tabl">info</th>
<th class="tabl">foto's</th>
</tr>
<?php
$link = #mysqli_connect("localhost", "root", "", "citylab");
if (!$link)
{
die("Connection failed: " . mysqli_connect_error());
}
if($gamesres === FALSE)
{
echo mysqli_error($link);
}
$gamesquery = "SELECT * FROM bedrijf;";
$gamesres = mysqli_query($link, $gamesquery);
$gamen = $row["gamen"];
if (mysqli_num_rows($gamesres) > 0)
{
while($gamesrow = mysqli_fetch_assoc($gamesres)) {
echo "<tr>";
echo "<td class='tabl'>" . $row["id"] . "</td>";
echo "<td class='tabl'>" . $row["naam"] . "</td>";
echo "<td class='tabl'>" . $row["adres"] . "</td>";
echo "<td class='tabl'>" . $row["telnr"] . "</td>";
echo "<td class='tabl'>" . $row["email"] . "</td>";
echo "<td class='tabl'><a href='" . $row["linkedin"] . "' target='_Blank'>Link</a></td>";
echo "<td class='tabl'><a href='" . $row["fb"] . "' target='_Blank'>Link</a></td>";
echo "<td class='tabl'><a href='" . $row["twitter"] . "' target='_Blank'>Link</a></td>";
echo "<td class='tabl'><a href='" . $row["eigensite"] . "' target='_Blank'>Link</a></td>";
echo "<td class='tabl'>" . $row["branchering"] . "</td>";
$personenquery = "SELECT * FROM personen WHERE bedrijfid =".$gamesrow["id"]." ;";
$personenres = mysqli_query($link, $personenquery);
if($personenres === FALSE)
{
echo mysqli_error($link);
}
if (mysqli_num_rows($personenres) > 0)
{
while($row = mysqli_fetch_assoc($personenres))
{
echo "<td class='tabl'>" . $row["naam"] . "</td>";
}
}
echo "</tr>";
}
}
?>
</table>
there is the code and i think i did something wrong here:
$gamesquery = "SELECT * FROM bedrijf;";
$gamesres = mysqli_query($link, $gamesquery);
$gamen = $row["gamen"];
if (mysqli_num_rows($gamesres) > 0)
{
while($gamesrow = mysqli_fetch_assoc($gamesres)) {
thanks in advance and i really hope someone could help me.
<?php
$result = mysqli_query($conn,"SELECT * FROM news ORDER BY date DESC
LIMIT 5")or die(mysql_error());
if (!$result) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
echo "<table align='left' CELLPADDING='50' >";
while($row = mysqli_fetch_array($result))
{
if ($row['photoid'] == NULL){
$date_string = $row['date'];
$date = strtotime($date_string);
$date = date('m/d/y', $date);
echo "<tr>";
echo "<td style='width: 750px'>" .$row['title'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td style='width: 700px'>" . $row['news'] . "</td>";
echo "<td style='width: 100px'>" . $date . "</td>";
echo "</tr>";
}
else
{
$result = mysqli_query($conn,"SELECT news.title,news.date,news.news,photo.photo FROM news, photo WHERE news.photoid = photo.photoid ORDER BY date DESC") or die(mysql_error());
$row = mysqli_fetch_array($result);
$date_string = $row['date'];
$date = strtotime($date_string);
$date = date('m/d/y', $date);
echo "<tr>";
echo "<td style='width: 750px'>" . $row['title'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td style='width: 700px'>" . $row['news'] . "</td>";
echo "<td style='width: 100px'>" . $date . "</td>";
echo "</tr>";
echo "<td style='width: 800px'>" . '<img height="300" width="300" src="data:image/jpeg;base64,'.base64_encode( $row["photo"] ).'" >' . "</td>";
}
}
echo "</table>";
mysqli_close($conn);
?>
SO the website shows a news column, the code gets the news data from the database, if there is a photoid (if the news has a photo to go with it) then it adds the news to the table with a photo. If there is no photo is adds the news to the table without one. Simple. At the moment for testing I have two news articles both with photos, the first one works perfectly then the second errors
Undefined index: photoid in
For the line if ($row['photoid'] == NULL){. There is a photoid.
You need to check if variable/key is set before checking the value. Try this:
if (isset($row['photoid']) && $row['photoid'] == NULL){
I am making a project on proposal management system and I am stuck on the pricing module. Here is my HTML DEMO. I have shown only required field in the output. INSERT queries below are correct.
I am trying to AUTOMATICALLY display the sum of the 'amount' in the 'total' each time the user presses 'save' button . The value of 'total' should increment when user presses 'save' either from 'add services' table or from 'add products' table. I am unsuccessful so far. HOW CAN I DO IT?
I have tried this: (Any other solution will be appreciated).
<td> <input type="text" name="amount" maxlength="15" id="amount" readonly="true" value=" <?php
if(isset($_POST['save'])|| isset($_POST['psave']))
{
$con= mysqli_connect("localhost","root","","my_db")or die("cannot connect");
$sql = "SELECT proposal_services.service_amount AMOUNT,proposal_products.product_amount AMOUNT1, FROM proposal_services INNER JOIN proposal_products ON proposal_products.proposal_id=proposal_services.proposal_id";
$result= mysqli_query($con,$sql);
$row = mysqli_fetch_array($result);
foreach ( $row as $records )
{
$sum = str_replace(",", "", $records['AMOUNT']) + str_replace(",", "", $records['AMOUNT1']);
}
echo number_format( $sum, 2 );
}
?> "/></td>
my php code where I insert and display results is:
insert_services.php
<?php
session_start();
$prop_id = $_SESSION['propl_id'];
$user_id = $_SESSION['sign_user_id'];
$con = mysqli_connect("localhost","root","","my_db");
$name = $_POST['ser_name'];
$desc = $_POST['txt'];
$price = $_POST['price'];
$per = $_POST['per'];
$quantity = $_POST['quantity'];
$amount = $_POST['amount'];
if(mysqli_query($con,"INSERT INTO proposal_services(proposal_id,user_id,service_name,service_description,service_price,per,service_quantity,service_amount) VALUES('$prop_id','$user_id','$name','$desc','$price','$per','$quantity','$amount')"))
$sql= "select * FROM proposal_services WHERE proposal_id='$prop_id' ";
$result= mysqli_query($con,$sql);
echo "<table border='1'>
<tr>
<th align='center'>Service Name</th>
<th align='center'>Description</th>
<th align='center'>Price</th>
<th align='center'>per</th>
<th align='center'>Quantity</th>
<th align='center'>Amount</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<div id='change'>";
echo "<tr>";
echo "<td align='center'>" . $row['service_name'] . "</td>";
echo "<td align='center'>" . $row['service_description']. "</td>";
echo "<td align='center'>" . $row['service_price']. "</td>";
echo "<td align='center'>" . $row['per']. "</td>";
echo "<td align='center'>" . $row['service_quantity']. "</td>";
echo "<td align='center'>" . $row['service_amount']. "</td>";
echo "</tr>";
echo "</div>";
}
echo "</table>";
?>
insert_products.php
<?php
session_start();
$prop_id = $_SESSION['propl_id'];
$user_id = $_SESSION['sign_user_id'];
$con = mysqli_connect("localhost","root","","my_db");
$name = $_POST['pro_name'];
$desc = $_POST['txt'];
$price = $_POST['price'];
$per = $_POST['per'];
$quantity = $_POST['quantity'];
$amount = $_POST['amount'];
if(mysqli_query($con,"INSERT INTO proposal_products(proposal_id,user_id,product_name,product_description,product_price,per,product_quantity,product_amount) VALUES('$prop_id','$user_id','$name','$desc','$price','$per','$quantity','$amount')"))
$sql= "select * FROM proposal_products WHERE proposal_id='$prop_id'";
$result= mysqli_query($con,$sql);
echo "<table border='1'>
<tr>
<th>Product Name</th>
<th>Description</th>
<th>Price</th>
<th>per</th>
<th>Quantity</th>
<th>Amount</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['product_name'] . "</td>";
echo "<td>" . $row['product_description'] . "</td>";
echo "<td>" . $row['product_price'] . "</td>";
echo "<td>" . $row['per'] . "</td>";
echo "<td>" . $row['product_quantity'] . "</td>";
echo "<td>" . $row['product_amount'] . "</td>";
echo "<td align='center'>" . "<input type='button' value= 'edit'>" . "</td>";
echo "</tr>";
}
echo "</table>";
?>
I am generating a Dynamic table based on user's search result with those searched columns only.
The table is generated in AJAX page and coming back as response in another page.The pagination alone is not working.
please help.
My Code:
<?php
require_once('../Connections/finalkms.php');
$data = json_decode(stripslashes($_POST['data']), true);
$qry = " SELECT AssetId,";
$qry .= $data;
$qry .= " from Completedetails";
mysql_select_db($database_finalkms, $finalkms);
$query_getcolumns = $qry;
$getcolumns = mysql_query($query_getcolumns, $finalkms) or die(mysql_error());
$row_getcolumns = mysql_fetch_assoc($getcolumns);
$totalRows_getcolumns = mysql_num_rows($getcolumns);
if (($getcolumns)||(mysql_errno == 0))
{
echo "<table width='50%' class='table table-striped table-bordered table-hover' align='center' id='sample_2'>
<thead><tr id='vstr'>";
if (mysql_num_rows($getcolumns)>0)
{
$i = 0;
while ($i < mysql_num_fields($getcolumns))
{
echo "<th align='center'>". mysql_field_name($getcolumns, $i) . "</th>";
$i++;
}
echo "</tr></thead>";
while ($rows = mysql_fetch_array($getcolumns,MYSQL_ASSOC))
{
echo "<tbody><tr>";
foreach ($rows as $data)
{
echo "<td align='center'>". $data . "</td>";
}
}
}else{
echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr></tr>";
}
echo "</tbody></table>";
}else{
echo "Error in running query :". mysql_error();
}
?>
Here's My Java script code:
<script>
$("#sample_2").dataTable();
</script>
This is the solution:
<?php
require_once('../Connections/finalkms.php');
$data = json_decode(stripslashes($_POST['data']), true);
$qry = " SELECT AssetId,";
$qry .= $data;
$qry .= " from Completedetails";
mysql_select_db($database_finalkms, $finalkms);
$query_getcolumns = $qry;
$getcolumns = mysql_query($query_getcolumns, $finalkms) or die(mysql_error());
$row_getcolumns = mysql_fetch_assoc($getcolumns);
$totalRows_getcolumns = mysql_num_rows($getcolumns);
if (($getcolumns)||(mysql_errno == 0))
{
echo "<table width='50%' class='table table-striped table-bordered table-hover' align='center' id='sample_2'>
<thead><tr id='vstr'>";
if (mysql_num_rows($getcolumns)>0)
{
$i = 0;
while ($i < mysql_num_fields($getcolumns))
{
echo "<th align='center'>". mysql_field_name($getcolumns, $i) . "</th>";
$i++;
}
echo "</tr></thead>";
while ($rows = mysql_fetch_array($getcolumns,MYSQL_ASSOC))
{
echo "<tr>"; //removed body tag here
foreach ($rows as $data)
{
echo "<td align='center'>". $data . "</td>";
}
}
}else{
echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr></tr>";
}
echo "</table>";
}else{
echo "Error in running query :". mysql_error();
}
?>
Here's My Java script code:
<script>
$("#sample_2").dataTable();
</script>