I'm trying to apply color on alternate lines in the following code in PHP, but I already tried in various shapes and examples here in the forum and it did not solve. I need only leave one white line, and another gray, filling in according to the mysql query. I would like to make this list without using CSS. Can someone help?
<style type="text/css">
.whiteBackground { background-color: #fff; }
.grayBackground { background-color: #ccc; }
</style>
<table class="table-bordered" style="text-align: center; margin-left: -50px; font-family: Verdana, Geneva, sans-serif; margin-top: 20px;" border="0" cellspacing="1" cellpadding="2" align="center">
<table class="table-bordered" style="text-align: center; margin-left: -50px; font-family: Verdana, Geneva, sans-serif; margin-top: 20px;" border="0" cellspacing="1" cellpadding="2" align="center">
<thead>
<tr>
<th style="font-size: 1em; padding: 5px;">Client</th>
<th style="font-size: 1em; padding: 5px;">Tech</th>
<th style="font-size: 1em; padding: 5px;">Status</th>
<th style="font-size: 1em; padding: 5px;">Data</th>
<th style="font-size: 1em; padding: 5px;">Start</th>
<th style="font-size: 1em; padding: 5px;">End</th>
<th style="font-size: 1em; padding: 5px;">Total Hours</th>
</tr>
</thead>
<tbody>
<?php
$x++;
$class = ($x%2 == 0)? 'whiteBackground': 'graybackground';
echo "<tr class='$class'>";
foreach ($os as $c) {
$query = "SELECT nome from users where idUsers=$c->users_id";
$data= $this->db->query($query)->result();
echo '<tr >';
echo '<td >' . $c->nameclient . '</td>';
echo '<td >' . $data[0]->name . '</td>';
echo '<td >' . $c->status . '</td>';
echo '<td >' . date('d/m/Y', strtotime($c->startDate)) . '</td>';
echo '<td >' . $c->startTime . '</td>';
echo '<td >' . $c->endTime . '</td>';
$time_diff = strtotime($c->endTime) - strtotime($c->startTime);
$var= $time_diff/60;
echo '<td >'.date('H:i', mktime(0,$var)).'</td>';
echo '</tr>';
}
?>
I'll show the example of using % (or Mod) to alternate the background color on a simple array.
$arr = array("fred","tim","bob","jimmy");
echo "<table>";
$i=1;
foreach ($arr as $row) {
$class = ($i % 2) ? " odd": " even"; //even or odd?
echo "<tr class=" . $class . ">";
echo "<td>" . $row . "</td>";
echo "</tr>";
$i++;
}
echo "</table>"
?>
<style type="text/css">
.even, .odd {
color:white;
}
.even {
background-color: blue;
}
.odd {
background-color: red;
}
</style>
And, how to do it in purely CSS. (IE 9 or greater: https://www.w3schools.com/cssref/sel_nth-child.asp)
$arr = array("fred","tim","bob","jimmy");
echo "<table>";
$i=1;
foreach ($arr as $row) {
echo "<tr>";
echo "<td>" . $row . "</td>";
echo "</tr>";
$i++;
}
echo "</table>"
?>
<style type="text/css">
.even, .odd {
color:white;
}
table tr:nth-child(even) {
background-color: blue;
}
table tr:nth-child(odd) {
background-color: red;
}
</style>
Just change your css to this
<style type="text/css">
/* .whiteBackground { background-color: #fff; } */
/* .grayBackground { background-color: #ccc; } */
tbody tr:even{background-color:#fff;}
tbody tr:odd{background-color:#ccc;}
</style>
I dont think many people use the HTML attribut bgcolor anymore, but you can use it in the TR tag bgcolor="#cccccc". Or you can just use an inline style of background-color: #cccccc;
$highlight = false;
foreach ($os as $c)
{
$query = "SELECT nome from users where idUsers=$c->users_id";
$data= $this->db->query($query)->result();
$time_diff = strtotime($c->endTime) - strtotime($c->startTime);
$var= $time_diff/60;
$highlight = !$highlight;
echo '
<tr '.($highlight ? 'bgcolor="#cccccc"' : '').'>
<td >' . $c->nameclient . '</td>
<td >' . $data[0]->name . '</td>
<td >' . $c->status . '</td>
<td >' . date('d/m/Y', strtotime($c->startDate)) . '</td>
<td >' . $c->startTime . '</td>
<td >' . $c->endTime . '</td>
<td >'.date('H:i', mktime(0,$var)).'</td>
</tr>';
}
Related
Here is the generatepdf.php:
<?php
include('db.php');
require_once 'vendor/autoload.php';
ob_start();
?>
<?php
$student_id = 0;
if (isset($_GET['id'])) {
$student_id = $_GET['id'];
}
// var_dump($student_id);
$fetchUser = $conn->query("SELECT * from student where id = $student_id")->fetchAll(PDO::FETCH_ASSOC);
$subjects = $conn->query("SELECT * FROM subjects WHERE student_id = $student_id")->fetchAll(PDO::FETCH_ASSOC);
//
// var_dump($fetchUser);
// Student Info
$name = $fetchUser[0]['name'];
$rollno = $fetchUser[0]['rollno'];
$image = $fetchUser[0]['image'];
$center = $fetchUser[0]['center'];
$division = $fetchUser[0]['division'];
$academic_year = $fetchUser[0]['academic_year'];
$class = $fetchUser[0]['class'];
$session = $fetchUser[0]['session1'] . ' - ' . $fetchUser[0]['session2'];
$father = $fetchUser[0]['father'];
$stream = $fetchUser[0]['stream'];
$totalmarks = $fetchUser[0]['totalmarks'];;
$obtmarks = $fetchUser[0]['obtmarks'];
$marksinwords = $fetchUser[0]['marksinwords'];
$percentage = ($fetchUser[0]['obtmarks'] / $fetchUser[0]['totalmarks']) * 100;
$percentage = number_format($percentage, 2);
$todaysDate = gmdate("M d, Y", strtotime('now'));
$html = '
<html>
<head>
<style>
body {font-family: sans-serif;
font-size: 10pt;
}
p { margin: 0pt; }
table.items {
border: 0.1mm solid #000000;
}
td { vertical-align: top; }
.items td {
border-left: 0.1mm solid #000000;
border-right: 0.1mm solid #000000;
}
table thead td { background-color: #EEEEEE;
text-align: center;
border: 0.1mm solid #000000;
font-variant: small-caps;
}
.items td.blanktotal {
background-color: #EEEEEE;
border: 0.1mm solid #000000;
background-color: #FFFFFF;
border: 0mm none #000000;
border-top: 0.1mm solid #000000;
border-right: 0.1mm solid #000000;
}
.items td.totals {
text-align: right;
border: 0.1mm solid #000000;
}
.items td.cost {
text-align: "." center;
}
</style>
</head>
<body>
<!--mpdf
<htmlpageheader name="myheader">
<table width="100%"><tr>
<td width="80%" style="color:#000; "><span style="font-weight: bold; font-size: 14pt;">Online Marksheet For TELEGANA UNIVERSITY</span></td>
// <td width="20%" style="text-align: right;">Date: ' . $todaysDate . '<br />
</tr></table>
</htmlpageheader>
<htmlpagefooter name="myfooter">
<div style="border-top: 1px solid #000000; font-size: 9pt; text-align: center; padding-top: 3mm; ">
Page {PAGENO} of {nb}
</div>
</htmlpagefooter>
<sethtmlpageheader name="myheader" value="on" show-this-page="1" />
<sethtmlpagefooter name="myfooter" value="on" />
mpdf-->
<img style="margin-top: -50px;padding: 15px; border: 2px solid #000; height: 100px;margin: auto !important;width: 100px;background-size: contain;background-repeat: no-repeat;background-position: center;margin-left: 80px !important;" src="images/' . $image . '" class="img-thumbnail">
<table width="100%" style="font-family: serif;" cellpadding="10"><tr>
<td width="55%"><br /><br /><span style="font-weight: bold;">Name:</span> ' . $name . '<br /><span style="font-weight: bold;">Father:</span> ' . $father . '<br /><span style="font-weight: bold;">Center:</span> ' . $center . '<br /><span style="font-weight: bold;">Division:</span> ' . $division . '<br /><span style="font-weight: bold;">Class:</span> ' . $class . '</td>
<td width="5%"> </td>
<td width="40%"><br /><br /><span style="font-weight: bold;">Hall Ticket / Roll No:</span> ' . $rollno . '<br /><span style="font-weight: bold;">Session:</span> ' . $session . '<br /><span style="font-weight: bold;">Stream:</span> ' . $stream . '<br /><span style="font-weight: bold;">Year of Passing:</span> ' . $academic_year . '</td>
</tr></table>
<br />
<table class="items" width="100%" style="font-size: 9pt; border-collapse: collapse; " cellpadding="8">
<thead>
<tr>
<td width="15%">Sub Code</td>
<td width="40%">Subject Name</td>
<td width="10%">Theory</td>
<td width="15%">Practicals</td>
<td width="20%">Marks Secured</td>
</tr>
</thead>
<tbody>
<!-- ITEMS HERE -->
';
foreach ($subjects as $subject) {
$html .= '<tr>';
$html .= '<td align="center">' . $subject['subcode'] . '</td>';
$html .= '<td align="center">' . $subject['subject_name'] . '</td>';
$html .= '<td>' . $subject['total_marks'] . '</td>';
$html .= '<td class="cost">' . $subject['obtained_marks'] . '</td>';
$html .= '<td class="cost">' . $subject['marksinwords'] . '</td>';
$html .= '</tr>';
}
$html .= '
<tr style="border-top: 2px solid #000;">
<td style="border-top: 2px solid #000;" align="center" >Percentage: ' . $percentage . '</td>
<td style="border-top: 2px solid #000;" align="center"></td>
<td style="border-top: 2px solid #000;">' . $totalmarks . '</td>
<td style="border-top: 2px solid #000;" class="cost">' . $obtmarks . '</td>
<td style="border-top: 2px solid #000;" class="cost">' . $marksinwords . '</td>
</tr>
</tbody>
</table>
</body>
</html>
';
require_once 'bootstrap.php';
$mpdf = new \Mpdf\Mpdf([
'margin_left' => 10,
'margin_right' => 10,
'margin_top' => 30,
'margin_bottom' => 25,
'margin_header' => 10,
'margin_footer' => 10
]);
$mpdf->SetTitle("Online Marksheet");
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($html);
$mpdf->Output();
This is working perfectly fine in XAMPP for me, and is downloading the PDF every time I load the page.
But when I hosted these exact same files on cPanel's File Manager - it's only showing me a blank page. No errors. What can I do?
I've checked the PHP versions of both my XAMPP (v8.0) and PHP(v7.3) but that doesn't seem to be the issue (unless one of you think it is?)
To Troubleshoot:
Comment out
$mpdf->WriteHTML($html);
$mpdf->Output();
instead, just echo $html; first, just to see if all is correct.
Why?
Make sure that your html is not malformed.
If there's error messages or any php headers are sent already PDF will be corrupted and will show error on render.
Things to check before output();
All paths include/require paths are still correct or you uploaded them differently than your XAMPP?
Why ob_start() but I do not see where you ob_get_contents() and ob_end_clean() in the code? Effectively it would keep buffering without outputting. Server might be more strict than your XAMPP and gives you warning.
After all errors checked, paths corrected if were incorrect - your user input is not santised thats a big NO NO.
regarding your it's only showing me a blank page. No errors. What can I do? statement. There's either critical error and you need to check logs.
In this case, likely "require" path to bootstrap is incorrect.
If it's no errors in error logs, then likely your ob_start() would forbid you from outputting anything.
So I'm making a localhost site to keep track of my families medications (upwards of 50 of them). I'm working on a page of it to #print out tables for each of us (4 total individuals) for when we fill our med containers each Sunday. All that said, my wife asked me to get the <th> to show on each page (top and bottom).
I did some research and found a great answer to the basic problem: How to use HTML to print header and footer on every printed page of a document?
This is a great answer and I started there with the below table that is echo'd with PHP. I took out the PHP for now, but can add it if someone really needs it.. I use the PHP because the data is coming out of a SQL>Database>Table.
HTML (from PHP echo)
<table>
<thead>
<tr>
<th colspan='15' class='patientHeader'>[Family Member Name]'s Meds</th>
</tr>
<tr>
<th>Drug Names</th>
<th>Prescriber</th>
<th>Dose/Pill</th>
<th>Frequency</th>
<th>Rx Number</th>
<th>Time</td>
<th class='tinyBoxes'>M</th>
<th class='tinyBoxes'>T</th>
<th class='tinyBoxes'>W</th>
<th class='tinyBoxes'>T</th>
<th class='tinyBoxes'>F</th>
<th class='tinyBoxes'>S</th>
<th class='tinyBoxes'>S</th>
<th class='nf'>Next Fill</th>
</tr>
</thead>
<!-- BODY CONTENT -->
<tfoot>
<tr>
<th>Drug Names</th>
<th>Prescriber</th>
<th>Dose/Pill</th>
<th>Frequency</th>
<th>Rx Number</th>
<th>Time</td>
<th class='tinyBoxes'>M</th>
<th class='tinyBoxes'>T</th>
<th class='tinyBoxes'>W</th>
<th class='tinyBoxes'>T</th>
<th class='tinyBoxes'>F</th>
<th class='tinyBoxes'>S</th>
<th class='tinyBoxes'>S</th>
<th class='nf'>Next Fill</th>
</tr>
</tfoot>
</table>
CSS
#media print {
.menubar,
h1.viewable,
#pagewrapper,
#footer,
.subbar,
#screenblock {
display: none !important;
}
body {
background-color: white;
color: black;
font: 8pt Georgia, "Times New Roman", Times, serif;
line-height: 1.3;
}
#page {
margin: 1cm;
size: landscape;
}
h1 {
font-size: 24pt;
}
h2 {
font-size: 14pt;
margin-top: 25px;
}
aside h2 {
font-size: 18pt;
}
.body {
display: block;
width: 8.5in;
height: 11in;
text-align: center;
}
/*************************VIEW TABLE STUFF*************************/
table {
width: 100%;
border-spacing: 0px;
border: 1px sold black;
page-break-inside: avoid;
box-decoration-break: clone;
-webkit-box-decoration-break: clone;
page-break-after: always;
margin-bottom: 25px;
}
tr {
page-break-inside: avoid;
}
th {
font-weight: bold;
border: 1px solid black;
border-collapse: collapse;
height: 50px;
vertical-align: middle;
text-align:center !important;
}
td {
border: 1px solid black;
border-collapse: collapse;
vertical-align: middle;
text-align: center;
padding: 5px 0;
}
.smallBean {
font-size: smaller;
font-style: italic;
margin: 0px;
padding: 0px;
text-align: center;
font-size: 10pt;
}
.tinyBoxes {
width: 0.5cm;
height: 0.5cm;
font-weight: bold;
vertical-align: middle;
padding: .1cm;
}
.nf {
width: 100px !important;
}
.nf::after {
font-size: smaller;
font-style: italic;
margin: 0px;
padding: 0px;
text-align: center;
content: "\A or \A Refil Needed";
white-space: pre;
}
.onePage {
page-break-before: always !important;
page-break-after: always !important;
page-break-inside: avoid !important;
}
.patientHeader {
font-size: 0.4in;
font-variant: small-caps;
}
}
Here's the problem I run in to...
Within the gathering of the data and filling of the table, I use <td rowspan=''> and break down each medicine by when they are taken. When the table breaks on a row with this, the remaining <td rowspan='1'> get overlapped by the <thead>.
IMGUR Image of what the print looks like
**EDIT - ADDITIONAL INFORMATION **
I did chose the <thead> and <tfoot> option from that link I posted because I want them attached to the content and not the page.
To clarify a comment
$am = $row['am'];
$noon = $row['noon'];
$pm = $row['pm'];
$bed = $row['bed'];
$prn = $row['prn'];
$other = $row['other'];
if ($other != 1) {
if ($am == 1) {
echo "<td rowspan = '1'>AM</td>";
$am = 0;
} elseif ($noon == 1) {
echo "<td rowspan = '1'>Noon</td>";
$noon = 0;
} elseif ($pm == 1) {
echo "<td rowspan = '1'>PM</td>";
$pm = 0;
} elseif ($bed == 1) {
echo "<td rowspan = '1'>Bed</td>";
$bed = 0;
} elseif ($prn == 1) {
echo "<td rowspan = '1'>PRN</td>";
$prn = 0;
}
}
echo "<td tinyBoxes'></div><td class='tonyBoxes'></td><td class='tonyBoxes'></td><td class='tonyBoxes'></td>
<td class='tonyBoxes'></td><td class='tonyBoxes'></td><td class='tonyBoxes'></td>";
echo "<td rowspan='" . $rows . "' style='width:125px !important'>" . $nextFill . "</td>";
echo "</tr>";
if (($rows > 1) && ($other != 1)) {
if ($noon == 1) {
echo "<tr>";
echo "<td rowspan = '1'>Noon</td>";
echo "<td tinyBoxes'></div><td class='tonyBoxes'></td><td class='tonyBoxes'></td><td class='tonyBoxes'></td>
<td class='tonyBoxes'></td><td class='tonyBoxes'></td><td class='tonyBoxes'></td>";
echo "</tr>";
}
if ($pm == 1) {
echo "<tr>";
echo "<td rowspan = '1'>PM</td>";
echo "<td tinyBoxes'></div><td class='tonyBoxes'></td><td class='tonyBoxes'></td><td class='tonyBoxes'></td>
<td class='tonyBoxes'></td><td class='tonyBoxes'></td><td class='tonyBoxes'></td>";
echo "</tr>";
}
if ($bed == 1) {
echo "<tr>";
echo "<td rowspan = '1'>Bed</td>";
echo "<td tinyBoxes'></div><td class='tonyBoxes'></td><td class='tonyBoxes'></td><td class='tonyBoxes'></td>
<td class='tonyBoxes'></td><td class='tonyBoxes'></td><td class='tonyBoxes'></td>";
echo "</tr>";
}
if ($prn == 1) {
echo "<tr>";
echo "<td rowspan = '1'>PRN</td>";
echo "<td tinyBoxes'></div><td class='tonyBoxes'></td><td class='tonyBoxes'></td><td class='tonyBoxes'></td>
<td class='tonyBoxes'></td><td class='tonyBoxes'></td><td class='tonyBoxes'></td>";
echo "</tr>";
}
}
The issue falls during these <td rowspan = '1'> tags
Some work and I figured out a bit of a workaround - not a great one, but it does achieve the purpose I was going for...
I removed the <tfoot> - it wasn't necessary and was where the problem was being caused.
I found an error in my <td class='tinyBoxes'> cells - some said "tonyBoxes" and a few were missing the class='` portion
echo "<td class='tinyBoxes'></div><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>
<td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>";
echo "<td rowspan='" . $rows . "' style='width:125px !important;font-size:0.15in;'>" . $nextFill . "</td>";
echo "</tr>";
if (($rows > 1) && ($other != 1)) {
if ($noon == 1) {
echo "<tr class='tiny'>";
echo "<td rowspan = '1'>Noon</td>";
echo "<td class='tinyBoxes'></div><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>
<td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>";
echo "</tr>";
}
if ($pm == 1) {
echo "<tr class='tiny'>";
echo "<td rowspan = '1'>PM</td>";
echo "<td class='tinyBoxes'></div><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>
<td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>";
echo "</tr>";
}
if ($bed == 1) {
echo "<tr class='tiny'>";
echo "<td rowspan = '1'>Bed</td>";
echo "<td class='tinyBoxes'></div><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>
<td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>";
echo "</tr>";
}
if ($prn == 1) {
echo "<tr class='tiny'>";
echo "<td rowspan = '1'>PRN</td>";
echo "<td class='tinyBoxes'></div><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>
<td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>";
echo "</tr>";
}
}
AND
/*
echo "
<tfoot>
<tr>
<th>Drug Names</th>
<th>Prescriber</th>
<th>Dose/Pill</th>
<th>Frequency</th>
<th>Rx Number</th>
<th>Time</td>
<th class='tinyBoxes'>M</th>
<th class='tinyBoxes'>T</th>
<th class='tinyBoxes'>W</th>
<th class='tinyBoxes'>T</th>
<th class='tinyBoxes'>F</th>
<th class='tinyBoxes'>S</th>
<th class='tinyBoxes'>S</th>
<th class='nf'>Next Fill</th>
</tr>
</tfoot>";
*/
I am new to programming, I have managed to create a page which fetches the data from MySQL.
I have used a jQuery plugin to freeze the first column and first row of my table.
The problem I am facing is, when I try to increase the width of a specific column it is not working.
Please help me to understand how do I increase width for specific column. This is my PHP and CSS for your reference.
Thanks.
PHP
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>Region Wise</title>
<link href="css/test.css" rel="stylesheet" media="screen" />
<header class="header">
<div class="titulosHeader">
<h2>Region Wise</h2>
</header>
</head>
<main class="main">
<div class="ContenedorTabla">
<?php
$sql = 'SELECT * from rgn_report';
$result = mysqli_query($con,$sql);
echo "<table id='pruebatabla' class='fht-table hoverTable'>
<thead>
<tr>
<th class='celda_encabezado_general' rowspan='3' style='height:100px;'>REGION</th>
<tr>
<th class='celda_encabezado_general' colspan='4'>KA</th>
<th class='space'></th>
<th class='celda_encabezado_general' colspan='4'>MI</th>
<th class='space'></th>
<th class='celda_encabezado_general' colspan='4'>OT</th>
<th class='space'></th>
<th class='celda_encabezado_general' colspan='4'>FA</th>
<th class='space'></th>
<th class='celda_encabezado_general' colspan='4'>HA</th>
</tr>
<tr>
<th class='celda_encabezado_general'>SOH</th>
<th class='celda_encabezado_general'>CY</th>
<th class='celda_encabezado_general'>CT</th>
<th class='celda_encabezado_general'>WC</th>
<th class='space'></th>
<th class='celda_encabezado_general'>SOH</th>
<th class='celda_encabezado_general'>CY</th>
<th class='celda_encabezado_general'>CT</th>
<th class='celda_encabezado_general'>WC</th>
<th class='space'></th>
<th class='celda_encabezado_general'>SOH</th>
<th class='celda_encabezado_general'>CY</th>
<th class='celda_encabezado_general'>CT</th>
<th class='celda_encabezado_general'>WC</th>
<th class='space'></th>
<th class='celda_encabezado_general'>SOH</th>
<th class='celda_encabezado_general'>CY</th>
<th class='celda_encabezado_general'>CT</th>
<th class='celda_encabezado_general'>WC</th>
<th class='space'></th>
<th class='celda_encabezado_general'>SOH</th>
<th class='celda_encabezado_general'>CY</th>
<th class='celda_encabezado_general'>CT</th>
<th class='celda_encabezado_general'>WC</th>
</tr>
</thead>";
echo "<tbody>";
while ($row = mysqli_fetch_array($result))
{
$rowhighlight = array("RGN1","RGN2","Grand Total");
if (in_array($row['rgn'],$rowhighlight)){
echo "<tr>";
echo "<td class='highlight_cell'>" . $row['rgn']."</td>";
echo "<td class='highlight_cell'>" . number_format($row['KA_SOH'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['KA_CY'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['KA_CT'])."</td>";
echo "<td class='highlight_cell'>" . $row['KA_CVR']."</td>";
echo "<td class='space'></td>";
echo "<td class='highlight_cell'>" . number_format($row['MI_SOH'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['MI_CY'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['MI_CT'])."</td>";
echo "<td class='highlight_cell'>" . $row['MI_CVR']."</td>";
echo "<td class='space'></td>";
echo "<td class='highlight_cell'>" . number_format($row['OT_SOH'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['OT_CY'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['OT_CT'])."</td>";
echo "<td class='highlight_cell'>" . $row['OT_CVR']."</td>";
echo "<td class='space'></td>";
echo "<td class='highlight_cell'>" . number_format($row['FA_SOH'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['FA_CY'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['FA_CT'])."</td>";
echo "<td class='highlight_cell'>" . $row['FA_CVR']."</td>";
echo "<td class='space'></td>";
echo "<td class='highlight_cell'>" . number_format($row['HA_SOH'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['HA_CY'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['HA_CT'])."</td>";
echo "<td class='highlight_cell'>" . $row['HA_CVR']."</td>";
echo "</tr>";}
else
{
echo "<tr>";
echo "<td class='excel_cell'>" . $row['rgn']."</td>";
echo "<td class='excel_cell'>" . number_format($row['KA_SOH'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['KA_CY'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['KA_CT'])."</td>";
echo "<td class='excel_cell'>" . $row['KA_CVR']."</td>";
echo "<td class='space'></td>";
echo "<td class='excel_cell'>" . number_format($row['MI_SOH'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['MI_CY'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['MI_CT'])."</td>";
echo "<td class='excel_cell'>" . $row['MI_CVR']."</td>";
echo "<td class='space'></td>";
echo "<td class='excel_cell'>" . number_format($row['OT_SOH'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['OT_CY'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['OT_CT'])."</td>";
echo "<td class='excel_cell'>" . $row['OT_CVR']."</td>";
echo "<td class='space'></td>";
echo "<td class='excel_cell'>" . number_format($row['FA_SOH'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['FA_CY'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['FA_CT'])."</td>";
echo "<td class='excel_cell'>" . $row['FA_CVR']."</td>";
echo "<td class='space'></td>";
echo "<td class='excel_cell'>" . number_format($row['HA_SOH'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['HA_CY'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['HA_CT'])."</td>";
echo "<td class='excel_cell'>" . $row['HA_CVR']."</td>";
echo "</tr>";
}
}
echo "</tbody>";
echo "</table>";
mysqli_close($con);
?>
</div>
</main>
<script src="js/jquery-1.11.0.min.js"></script>
<script src="js/jquery.CongelarFilaColumna.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#pruebatabla").CongelarFilaColumna({Columnas:1});
});
</script>
</body>
</html>
CSS
*{
margin: 0;
padding: 0;
border:0;
}
.header, .main {
display: inline-block;
height: auto;
width: 100%;
}
.titulosHeader {
height: auto;
}
.ContenedorTabla {
height: 540px;
border: 1px solid green;
overflow: auto;
position: relative;
max-width:auto;
}
.fht-table,
.fht-table thead,
.fht-table tfoot,
.fht-table tbody,
.fht-table tr,
.fht-table th,
.fht-table td
{
margin: 0;
}
.fht-table{
height: auto;
width: auto;
border-collapse: collapse;
border-spacing: 0;
border: 0 none;
table-layout:fixed;
}
.fht-table th,.fht-table td {
overflow: hidden;
table-layout:fixed;
}
.fht-table-wrapper,
.fht-table-wrapper .fht-thead,
.fht-table-wrapper .fht-tfoot,
.fht-table-wrapper .fht-fixed-column .fht-tbody,
.fht-table-wrapper .fht-fixed-body .fht-tbody,
.fht-table-wrapper .fht-tbody {
overflow: hidden;
position: relative;
}
.fht-table-wrapper .fht-fixed-body .fht-tbody,
.fht-table-wrapper .fht-tbody {
overflow: auto;
}
.fht-table-wrapper .fht-table .fht-cell {
overflow: hidden;
height: 1px;
}
.fht-table-wrapper .fht-fixed-column,
.fht-table-wrapper .fht-fixed-body {
top: 0;
left: 0;
position: absolute;
}
.fht-table-wrapper .fht-fixed-column {
z-index: 1;
}
.fht-fixed-body .fht-thead table {
margin-right: 20px;
border: 0 none;
}
.celda_encabezado_general {
background-color: #4BACC6;
border: 1px solid black;
color: #ffffff;
text-align: center;
font-size: 12px;
font-family: Calibri, sans-serif;
white-space: nowrap;
}
._Separador{
background-color: #fff;
height: 12px;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
width: 7px;
}
._Separador div{
width: 4px;
}
.celda_normal {
background-color: #fff;
border: 1px solid #ccc;
padding: 2px 4px;
}
.excel_cell{
border: 1px solid black;
color: #222;
text-align: center;
font-size: 11px;
font-weight: normal;
padding: 5px;
empty-cells: show;
font-family: Calibri, sans-serif;
white-space: nowrap;
}
._cell_header{
background-color: #EEE;
}
._cell_Default{
background-color: #FFF;
text-align: left;
}
.excel_cell div{
width: 30px;
height: 20px;
}
.highlight_cell{
border: 2px solid black;
color: #222;
text-align: center;
font-size: 11px;
font-weight: bold;
padding: 5px;
empty-cells: show;
font-family: Calibri, sans-serif;
white-space: nowrap;
}
.hoverTable tr:hover {
background-color: grey;
}
.space{
border: none;
empty-cells: show;
background-color:grey;
width:10px;
}
I am trying to make a table for private messages that an user receives.
This is my code:
<table>
<?php
foreach ($mesaje as $mesaj)
{
foreach ($users as $user)
echo '<tr>';
{
if ($user->user_id == $mesaj->expeditor_id && Auth::user()->user_id == $mesaj->destinatar_id)
{
echo '<td style = " padding: 5px 0px 0px 100px;">' . $user->username . '</td>';
}
if (Auth::user()->user_id == $mesaj->destinatar_id)
{
echo '
<td style = " padding: 5px 0px 0px 195px;">' . $mesaj->subiect . '</td>
<td style = " padding: 5px 0px 0px 215px;">' . $mesaj->data_mesajului . '</td>
';
}
}
}
echo '</tr>'; ?>
</table>
Expeditor_id = the id of the user that sends the message
destinatar_id = the id of the user that receives the message
I want it to be a message then on another line another message(username, the subject and the data), I don't know why some usernames are displayed, some are not, can anyone give me a solution please?
try this
<table>
#foreach ($mesaje as $mesaj)
#foreach ($users as $user)
#if ($user->user_id == $mesaj->expeditor_id && Auth::user()->user_id == $mesaj->destinatar_id)
<tr>
<td style=" padding: 5px 0px 0px 100px;">{{$user->username}}</td>
<td style=" padding: 5px 0px 0px 195px;">{{$mesaj->subiect}}</td>
<td style=" padding: 5px 0px 0px 215px;"> {{$mesaj->data_mesajului}}</td>
</tr>
#endif
#endforeach
#endforeach
</table>
In your IF condition you need to use second IF condition
FOR Example :
<table>
<?php
foreach ($mesaje as $mesaj)
{
foreach ($users as $user)
echo '<tr>';
{
if ($user->user_id == $mesaj->expeditor_id && Auth::user()->user_id == $mesaj->destinatar_id)
{
echo '<td style = " padding: 5px 0px 0px 100px;">' . $user->username . '</td>';
if (Auth::user()->user_id == $mesaj->destinatar_id)
{
echo '
<td style = " padding: 5px 0px 0px 195px;">' . $mesaj->subiect . '</td>
<td style = " padding: 5px 0px 0px 215px;">' . $mesaj->data_mesajului . '</td>
';
}
}
}
}
echo '</tr>'; ?>
</table>
Is there a way to wrap the text within the database?
I have a address being added into the database under the address column, but whenever I try to output the database through PHP it shows that the address column is seriously long which goes all the way out of the range of the paper size. Is there a method I could wrap these text into a specific amount of letters and have it line break on the output file or within the database?
edit: updated question with code
CODE:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>UGGL PEUI Customer Dividend - 12-01-2014</title>
<style type="text/css">
body,td,th {
font-family: Lato, Calibri, Arial, sans-serif;
font-style: normal;
font-weight: normal;
font-size: 12px;
}
body {
background: #C28E33;
color: #E6FFF2;
}
table{
border: 0px solid black;
border-spacing: 0px;
}
table thead tr{
font-family: Arial, monospace;
font-size: 14px;
}
table thead tr th{
border-bottom: 2px solid black;
border-top: 1px solid black;
margin: 0px;
padding: 2px;
background-color: #cccccc;
font-weight:bold
}
table tr {
font-family: arial, monospace;
color: black;
font-size:12px;
background-color: white;
}
table tr.odd {
background-color: #AAAAAA;
}
table tr td, th{
border-bottom: 1px solid black;
padding: 2px;
}
a:link{
font-family:arial, monospace;
text-decoration: none;
color: teal;
}
a:hover{
text-decoration: underline;
}
a:visited{
color:black;
text-decoration: none;
}
</style>
</head>
<body>
<?php
// HTML Table Output
echo
"<table border='1'>
<thead>
<tr>
<th>ID</th>
<th>Purchase Date</th>
<th>Mature Date</th>
<th>Amount</th>
<th>Beneficiary First Name</th>
<th>Beneficiary Last Name</th>
<th>Beneficiary ID</th>
<th>Beneficiary Contact No.</th>
<th>Beneficiary Address</th>
<th>Bank Account Name</th>
<th>Bank Account No.</th>
<th>Bank Swift Code</th>
<th>Bank Name</th>
<th>Bank Address</th>
<th>Bank Contact No.</th>
<th>Agent Name</th>
<th>Dec. 1, 2014 (Days)</th>
<th>Dec. 1, 2014 (Dividend)</th>
</thead>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['purchase_date'] . "</td>";
echo "<td>" . $row['mature_date'] . "</td>";
echo "<td>" . $row['unit'] . "</td>";
echo "<td>" . $row['beneficiary_first'] . "</td>";
echo "<td>" . $row['beneficiary_last'] . "</td>";
echo "<td>" . $row['beneficiary_id'] . "</td>";
echo "<td>" . $row['beneficiary_no'] . "</td>";
echo "<td>" . $row['beneficiary_add'] . "</td>";
echo "<td>" . $row['bank_acc_name'] . "</td>";
echo "<td>" . $row['bank_acc_no'] . "</td>";
echo "<td>" . $row['bank_swift'] . "</td>";
echo "<td>" . $row['bank_name'] . "</td>";
echo "<td>" . $row['bank_add'] . "</td>";
echo "<td>" . $row['bank_no'] . "</td>";
echo "<td>" . $row['agent'] . "</td>";
echo "<td>" . $row['first_days'] . "</td>";
echo "<td bgcolor=#E6FFF2><b>" . $row['first_payment'] . "</b></td>";
echo "</tr>";
}
echo "</table>";
// Close MySQL
mysqli_close($con);
?>
</body>
</html>
You can use two CSS properties:
<style>
.your-element{
word-wrap:break-word;
word-break:break-all;
}
</style>
Demo
References:
Word Wrap
Word Break