I'm making a localhost website that keeps track of my family's medications as well as has weekly print out sheets that we use to make sure all the meds to in all the proper containers, and if any are missing, we know what to pick up at the pharmacy...
I am using #media print { #page {size: letter}...} to make sure the printed pages are set the right direction (vs. landscape).
The problem I'm running in to is aesthetics...
Since not every pill is taken at every "time" of the day, I have the forms only list the rows (designated in the picture below as "AM NOON PM BED PRN NOTES") that need to be used for that specific med. Originally I did this with using rowspan='$rows' which calculated out great and worked fine - until I printed it. It would break the rows at PM or Bed because according to the system, it was a new <tr> and could page-break-after.
I've since started using a table inside the main table
echo "<table id='printRxTable'>
<thead>
<tr><th class='patientHeader' colspan='14'>$patient</th></tr>
<tr><th>Drug Names</th><th>Prescriber</th><th>Dose/Pill</th><th>Directions</th><th style='width:100px !important'>Rx Number</th>
<th class='tinyBoxes1'>TOD</th><th class='tinyBoxes'>M</th><th class='tinyBoxes'>Tu</th><th class='tinyBoxes'>W</th><th class='tinyBoxes'>Th</th>
<th class='tinyBoxes'>F</th><th class='tinyBoxes'>Sa</th><th class='tinyBoxes2'>Su</th><th class='nf'>Next Fill</th></tr>
</thead>";
<!-- Skip all the content adding part -->
echo "<td class='noPad' colspan='8'>"; /**THIS IS THE CONTAINING <td> FOR THE TABLE IN THE TABLE**/
echo "<table id='tIt' class='tItPrep'>";
if ($tod['am'] == 1) {
echo "<tr><td class='tinyBoxes1'>am</td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>
<td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes2'></td></tr>";
$tod['am'] = 0;
}
if ($tod['noon'] == 1) {
echo "<tr><td class='tinyBoxes1'>noon</td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>
<td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes2'></td></tr>";
$tod['noon'] = 0;
}
if ($tod['pm'] == 1) {
echo "<tr><td class='tinyBoxes1'>pm</td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>
<td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes2'></td></tr>";
$tod['pm'] = 0;
}
if ($tod['bed'] == 1) {
echo "<tr><td class='tinyBoxes1'>bed</td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>
<td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes2'></td></tr>";
$tod['bed'] = 0;
}
if ($tod['prn'] == 1) {
echo "<tr><td class='tinyBoxes1'>prn</td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>
<td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes2'></td></tr>";
$tod['prn'] = 0;
}
echo "<tr><td class='tinyBoxes1 other'>Notes</td><td class='other' colspan='7'>$notes</td></tr>";
echo "</table>";
With CSS
#media print {
#page {
size: letter;
}
body {
-webkit-print-color-adjust: exact !important;
width: 8.5in;
}
.menubar,
h1.viewable,
#pagewrapper,
#footer,
.subbar,
#screenblock {
display: none !important;
}
#pp {
display: block !important;
}
body {
background-color: white;
color: black;
font: 8pt Georgia, "Times New Roman", Times, serif;
}
/*************BASIC TABLE STUFF*************/
table {
max-width: 8.5in;
max-height: 11in;
margin: 0.25in;
border-collapse: collapse;
}
table * {
text-align: center;
vertical-align: middle;
border-spacing: 0;
}
table>tr * {
page-break-inside: avoid;
border: 1px solid black;
}
table>tr {
break-inside: avoid;
}
td,
th {
border: 1px solid black;
border-collapse: collapse;
padding: 10px;
white-space: nowrap
}
th {
font-variant: small-caps;
padding: 5pt;
}
/*************CLASS TABLE STUFF*************/
#printRxTable {
width: 8in;
height: 10.5in;
margin: 0.25in;
}
td.noPad {
padding: 0px !important;
margin: 0px !important;
}
#tIt {
width: 100%;
border-collapse: collapse;
margin: 0px;
padding: 0px;
display: table;
}
table#tIt * {
border-collapse: collapse;
padding: 0px;
margin: 0px;
height: 8mm;
width: 8mm;
}
.tinyBoxes,
.tinyBoxes1,
.tinyBoxes2 {
font-weight: bold;
vertical-align: middle;
padding: 0mm 1mm;
font-variant: small-caps;
}
.tinyBoxes1 {
border-left: none !important;
}
.tinyBoxes2 {
border-right: none !important;
}
#tIt>tbody>tr:first-child>td {
border-top: none !important;
}
#tIt>tbody>tr>td.other {
border: none;
word-wrap: normal !important;
}
#tIt>tbody>tr>td.tinyBoxes1.other {
border-right: 1px solid black;
}
.prime {
font-weight: bold;
margin: 0px;
padding: 5px;
text-align: center;
}
.smallBean {
font-weight: normal !important;
font-style: italic;
margin: 0px;
padding: 0px;
text-align: center;
font-size: 8pt;
border: none !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.3in;
font-variant: small-caps;
}
/** SOME OTHER STUFF NOT RELATED TO THIS HERE**/
}
For whatever reason, I cannot get the cells (<td class='tinyBoxes'> or 1 or 2) to all line up.
I've set their widths (both in the <th> and <td>) but they keep shifting whenever something is in notes AKA <td class='other'>
Specific CSS to .other:
.tinyBoxes,
.tinyBoxes1,
.tinyBoxes2 {
font-weight: bold;
vertical-align: middle;
padding: 0mm 1mm;
font-variant: small-caps;
}
.tinyBoxes1 {
border-left: none !important;
}
#tIt>tbody>tr>td.other {
border: none;
word-wrap: normal !important;
}
#tIt>tbody>tr>td.tinyBoxes1.other {
border-right: 1px solid black;
}
Any help getting these to keep their alignment would be appreciated
I tried adding to the notes of one of the meds and here's what it does..
I added table-layout: fixed; and it comes close...
Every now and then a random row is 1px off at the TOD column
I ended up deleting the whole thing and starting from scratch - it actually worked though, so I guess we're good...
echo "<table id='mainMedList'><thead><tr><th colspan='100' style='text-align:center;font-weight:bold;font-variant:small-caps;font-size:1cm'>$patient</th></tr><tr>";
echo "<th>Drug Name<div class='smallBean'>Alt Name</div></th><th>Prov</th><th>Dose/Pill</th><th>Q/F</th><th class='rx'>Rx Number</th><th class='tiny'>TOD</th>";
echo "<th class='tiny'>M</th><th class='tiny'>T</th><th class='tiny'>W</th><th class='tiny'>T</th><th class='tiny'>F</th>";
echo "<th class='tiny'>S</th><th class='tiny'>S</th><th class='nf'>Next Fill</tr></tr></thead>";
// SOME API DATA STUFF THAT'S NOT REALLY RELIVENT GOES HERE
echo "<tbody class='trg'>";
echo "<tr>";
echo "<td rowspan='$rows'>$rxPrimeName<div class='smallBean'>$rxAltName</div></td>";
echo "<td rowspan='$rows'>$prescriber</td>";
echo "<td rowspan='$rows'>$dpp $dppMetric</td>";
echo "<td rowspan='$rows'>" . $frequency . "x $freqMetric</td>";
echo "<td rowspan='$rows' class='rx'>$rxID</td>";
/*********TABLE IN TABLE*********/
echo "<td colspan='8' class='tItHolder'><table id='tIt'>";
if ($tod['am'] == 1) {
echo "<tr><td>am</td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>
<td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td></td></tr>";
$tod['am'] = 0;
}
if ($tod['noon'] == 1) {
echo "<tr><td>noon</td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>
<td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td></td></tr>";
$tod['noon'] = 0;
}
if ($tod['pm'] == 1) {
echo "<tr><td>pm</td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>
<td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td></td></tr>";
$tod['pm'] = 0;
}
if ($tod['bed'] == 1) {
echo "<tr><td>bed</td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>
<td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td></td></tr>";
$tod['bed'] = 0;
}
if ($tod['prn'] == 1) {
echo "<tr><td>prn</td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td>
<td class='tinyBoxes'></td><td class='tinyBoxes'></td><td class='tinyBoxes'></td><td></td></tr>";
$tod['prn'] = 0;
}
if ($other == 1) {
echo "<tr><td>Notes</td><td class='notes' colspan='7'>$notes</td></tr>";
}
echo "</tr>";
echo "</table></td>";
/*********END TABLE IN TABLE*********/
echo "<td rowspan='$rows'>$nextFill</td>";
echo "</tr>";
echo "</tbody>";
}
echo "</table>";
With CSS
table {
max-width: 8.5in;
margin: 0.25in;
border-collapse: collapse;
}
table * {
text-align: center;
vertical-align: middle;
border-spacing: 0;
border-collapse: collapse;
padding: 10px;
}
th {
font-variant: small-caps;
padding: 5pt;
}
/*************CLASS TABLE STUFF*************/
/**************MAIN MEDS STUFF**************/
table#mainMedList {
break-inside: avoid !important;
break-before: page !important;
break-after: page !important;
}
table#mainMedList,
table#tIt {
margin: 0px;
padding: 0px;
height: 10mm;
border: none;
table-layout: fixed;
}
table#mainMedList *,
table#tIt * {
width: fit-content;
}
table#mainMedList td.tItHolder {
padding: 0px;
margin: 0px;
width: 2.5in !important;
}
table#mainMedList th,
table#mainMedList td,
table#tIt th,
table#tIt td {
margin: 0px;
padding: 2mm;
}
table#mainMedList th,
table#mainMedList td {
border: 1px solid black;
}
table#mainMedList th.rx,
table#mainMedList td.rx {
width: 1in !important;
white-space: nowrap;
}
table#mainMedList>thead>tr>th.tiny {
width: 0.34375in;
padding: 2mm;
}
table#mainMedList>tbody>tr>td>table#tIt * {
margin: 0px;
padding: 0px;
border: none;
}
table#mainMedList>tbody>tr>td>table#tIt>tbody>tr * {
width: 0.34375in;
padding: 2mm;
font-variant: small-caps;
}
table#mainMedList>tbody>tr>td>table#tIt>tbody>tr>td {
border: 1px solid black;
}
table#mainMedList>tbody>tr>td>table#tIt>tbody>tr:first-child * {
border-top: none;
}
table#mainMedList>tbody>tr>td>table#tIt>tbody>tr:last-child * {
border-bottom: none;
}
table#mainMedList>tbody>tr>td>table#tIt>tbody>tr>td:first-child {
border-left: none;
}
table#mainMedList>tbody>tr>td>table#tIt>tbody>tr>td:last-child {
border-right: none;
}
table#mainMedList th.nf::after {
white-space: pre;
content: "\A or \A Refil Needed";
font-style: italic;
font-size: smaller;
}
table#mainMedList th {
font-variant: small-caps;
}
div.smallBean {
font-style: italic;
font-size: smaller;
text-align: center !important;
width: 100% !important;
margin: 0px;
padding: 0px;
}
tbody.trg {
display: table-row-group;
}
td.notes {
text-align: left;
width: 100% !important;
}
Related
I have a site where a user can post an image, along with some other information about said image. I have a sidebar for users to navigate to other parts of that specific side of my site.
It looks like it is displaying outside the div that I intended and envisioned all posts would be under, and it's worth mentioning that upon each new post, it is appearing farther and farther outside it's original intended place until reaching the body.
Here's what I mean. The screenshots are zoomed out screenshots of the site.
Just below is the code to the container which contains all my code for the tabs and posts, above that is just the "Answer Key" title, and the posting modal that the button to the right of it pulls out. Below it is the php that sends all the info the user inputted into the modal to the database. Apologies for the slight messiness.
<div id="container" class="row">
<div class="tab col-sm-3 border border-end-0 border-start-0" id="sidenav">
<ul style="list-style-type:none;padding:0;margin:0;" class="text-end" id="menu">
<li>
<a class="tablinks">Home</a>
</li>
<li>
<a class="tablinks">Calculators</a>
</li>
</ul>
</div>
<div id="entirepost" class="col-sm-9">
<?php
$query = mysqli_query($conn,"SELECT *,UNIX_TIMESTAMP() - sub_date_created AS TimeSpent from submission LEFT JOIN user on user.user_id = submission.sub_user_id order by submission_id DESC")or die(mysqli_error());
while($submission_row=mysqli_fetch_array($query)){
$id = $submission_row['submission_id'];
$upid = $submission_row['sub_user_id'];
$posted_by = $submission_row['firstname']." ".$submission_row['lastname'];
?>
<div id="posts">
<?php
if((isset($_SESSION['role']) && $_SESSION['role'] == "admin")){
echo "<a style='float:right; font-size: large;' class='btn btn-outline-danger' href='deletesubmission.php?id=" . $id . "'><b>×</b></a>";
}
elseif((isset($_SESSION['role']) && $_SESSION['role'] == "developer")){
echo "<a style='float:right; font-size: large;' class='btn btn-outline-danger' href='deletesubmission.php?id=" . $id . "'><b>×</b></a>";
}
elseif((isset($_SESSION['user_id']) && $_SESSION['user_id'] == $upid)) {
echo "<a style='float:right; font-size: large;' class='btn btn-outline-danger' href='deletesubmission.php?id=" . $id . "'><b>×</b></a>";
}
else {
echo "";
}
?>
<h3><?php echo $submission_row['sub_title']; ?></h3>
<h5>
<?php echo "<span class='badge rounded-pill' id='grade" . $submission_row['grade'] . "Flare'>" . $submission_row['grade'] . " Grade</span>"; ?>
<?php echo $submission_row['teacher']; ?> · <?php echo $submission_row['subject']; ?><br>
</h5>
<img id="uploadedImage" src="<?php echo "images//" . $submission_row['image_url'] ?>"/>
<p>
<?php echo $submission_row['sub_content'];?>
<!-- </?php echo "images//" . $submission_row['image_url'] ?><br> -->
<table id="submissionInfoTable">
<thead>
<tr>
<th width="25%">Assigned</th>
<th>Due</th>
</tr>
</thead>
<tbody>
<tr>
<td><i><?php echo date('F d, Y', $submission_row['assigned']) ?></i></td>
<td><i><?php echo date('F d, Y', $submission_row['due']) ?></i></td>
</tr>
</tbody>
<tbody>
<tr>
<td colspan="2">
<?php echo "<b>" . $submission_row['weight'] . "%</b> of your grade"; ?>
<i style="color:grey" class="bi bi-info-circle" data-bs-toggle="tooltip" title="Assignments may weigh differently depending on the teacher's grading system and how many other assignments are under this weight"></i>
</td>
</tr>
</tbody>
</table>
</p>
<small>
<i>
<?php echo $posted_by; ?>
</i>
<?php
if((isset($_SESSION['role']) && $_SESSION['role'] == "admin")){
echo "<span class='badge bg-primary'>Admin</span>";
}
elseif((isset($_SESSION['role']) && $_SESSION['role'] == "developer")){
echo "<span class='badge bg-primary'>Dev</span>";
}
else {
echo "";
}
?> ·
<?php
$days = floor($submission_row['TimeSpent'] / (60 * 60 * 24));
$remainder = $submission_row['TimeSpent'] % (60 * 60 * 24);
$hours = floor($remainder / (60 * 60));
$remainder = $remainder % (60 * 60);
$minutes = floor($remainder / 60);
$seconds = $remainder % 60;
if($days > 0)
echo date('F d, Y - H:i:sa', $submission_row['date_created']);
elseif($days == 0 && $hours == 0 && $minutes == 0)
echo "A few seconds ago";
elseif($days == 0 && $hours == 0)
echo $minutes.' minutes ago';
elseif($days == 0 && $hours == 1)
echo $hours.' hour ago';
elseif($days == 0 && $hours > 1)
echo $hours.' hours ago';
?>
</small>
<hr>
</div>
<br>
</div>
<?php
}
?>
</div>
#content {
margin: 20px;
}
#postcontent {
resize: none;
outline: none;
border: 1px solid rgb(192, 192, 192);
transition: all 0.5s ease;
border-radius: 16px;
padding: 10px;
width: 100%;
margin-top: 15px;
}
#postcontent:focus {
border: 1px solid #5865F2;
}
#entirepost {
border-right: 1px solid gray;
border-left: 1px solid gray;
/* border-radius: 5px; */
padding: 20px;
/* width:auto; */
}
#commentstextarea {
resize: none;
outline: none;
border: 1px solid gray;
transition: all 0.5s ease;
}
#commentstextarea:focus {
border: 1px solid #5865F2;
}
#comments {
margin-top: 10px;
}
#commentcontent {
margin-top: 1%;
padding-left:10px;
border-left: 3px solid #ccc;
width: 50%;
}
#commentstitle {
margin-left: 1%;
margin-top: 2%;
}
#title {
width: 100%;
font-size: 16px;
padding: 12px 20px 12px 40px;
margin-bottom: 12px;
outline: none;
border-radius: 16px;
background-color: transparent;
border: 1px solid rgb(192, 192, 192);
color: black;
transition: all 0.5s ease;
}
#title:focus {
border: 1px solid #5865F2;
}
#header {
padding:5px;
}
#NewSubmission {
background-color: transparent;
color: #3d4cf3;
border: 1px solid #a3a9f5;
}
#NewSubmission:hover {
background-color:#a3a9f5;
}
#PageTitle {
width:40%;
display: inline;
}
#container {
width: 100%;
padding-right: 0;
}
#sidenav {
padding-right: 0;
}
.tab {
float: left;
background-color: #f1f1f1;
transition: all 0.3s ease;
height: 100%;
}
.tab button, .tab a {
display: block;
text-decoration: none;
background-color: inherit;
color: black;
padding: 22px 16px;
width: 100%;
border: none;
outline: none;
text-align: left;
cursor: pointer;
transition: 0.3s;
font-size: 17px;
transition: all 0.3s ease;
}
.tab button:hover, .tab a:hover {
background-color: #ddd;
transition: all 0.3s ease;
}
.tab button.active, .tab a:hover {
background-color: #ccc;
transition: all 0.3s ease;
}
#search {
transition: all 0.3s ease;
width: 100%;
padding: 1%;
margin: 1%px;
outline: none;
border: none;
background-color: rgb(231, 230, 230);
}
.select2, input {
margin-top: 10px;
}
.select2 {
font-size: 16px;
outline: none;
border-radius: 16px;
}
.select2-selection {
-webkit-box-shadow: 0;
box-shadow: 0;
background-color: #fff;
border: 0;
border-radius: 16px;
color: #555555;
font-size: 14px;
outline: 0;
min-height: 48px;
text-align: left;
}
.select2-selection__rendered {
margin: 10px;
border-radius: 16px;
}
.select2-selection__arrow {
margin: 10px;
border-radius: 16px;
}
[class^='select2'] {
border-radius: 16px !important;
}
#weight, #DateAssign, #DateDue {
width: 80%;
font-size: 16px;
padding: 8px;
outline: none;
border-radius: 16px;
background-color: transparent;
border: 1px solid rgb(192, 192, 192);
color: black;
transition: all 0.5s ease;
}
#weight:focus {
border: 1px solid #5865F2;
}
.modal-dialog {
width: 50%;
}
/* #sidenav {
width: 17%;
background-color: #ccc;
}
#container {
width: 300px;
background-color: #ffcc33;
margin: auto;
}
#sidenav {
width: 17%;
background-color: #ccc;
float: left;
height: auto;
}
#entirepost {
width: 83%;
float: left;
height: auto;
}
#clear {
clear: both;
} */
input[type=file]::file-selector-button {
border: 1px solid #34495e;
padding: 6px;
border-radius: 16px;
background-color: transparent;
width: 150px;
transition: all 0.5s ease;
}
input[type=file]::file-selector-button:hover {
background-color: #34495e;
}
#uploadedImage {
border-radius: 12px;
max-width: 100%;
height: auto;
margin-bottom: 15px;
}
#submissionInfoTable {
width: 50%;
}
#submissionInfoTable th, td {
padding: 2px;
/* border: 1px solid black; */
}
#dropdownmenu i {
float:right;
}
#dropdownmenu {
width: 200px;
}
#grade9thFlare {
background-color: rgb(133, 244, 228);
color: rgb(50, 110, 121);
}
#grade10thFlare {
background-color: rgb(198, 244, 179);
color: rgb(50, 100, 54);
}
#grade11thFlare {
background-color: rgb(206, 213, 255);
color: rgb(50, 100, 145);
}
#grade12thFlare {
background-color: rgb(239, 222, 240);
color: rgb(148, 91, 206);
}
The two posts below the first are both underneath the sidebar and are not within the left and right borders of the first post. And, of course, the 2 posts at the bottom were not in there in the original code as shown above. the sidebar is using the bootstrap utility .col-sm-4 while the posts are all supposed to be using .col-sm-8.
This also seems to happen when I attempt to add a comments feature to another part of my site, the discussion board.
Maybe my googling- I mean, programming skills aren't as good as they usually are, but a good amount of research has yielded no results for my specific issue.
in #entirepost use these
If you want your posts to be displayed horizontally
`display: flex;
align-items: flex-start;
justify-content: center;
flex-direction: row;`
and for vertical display use
display: flex;
align-items: flex-start;
justify-content: center;
flex-direction: column;
Kindly inform me if it did not helped ...
I have two tables that are "To-do Tasks" and "Completed Tasks". I don't know why when I add new tasks to the To-do Tasks table, the table grow bigger and start overlapping the Completed Tasks table. I did set the max-width for the table to stop it but it didn't help. Can someone teach me how to fix it? Thank you
$displayQuery="SELECT * FROM incomplete where owner=:owner";
$displayTask= $conn->prepare($displayQuery);
$displayTask->bindValue(':owner', $owner);
$displayTask->execute();
$allTask=$displayTask->fetchAll();
echo "<table class=\"incomplete_table\"><caption>To-do Tasks</caption><tr><th>ID</th><th>Title</th><th>Description</th><th>Due Date</th><th>Time</th><th colspan='3'>Button</th></tr>";
if(count($allTask) > 0)
{
foreach ($allTask as $row) {
echo "<tr><td>".$row["id"]."</td><td>".$row["title"]."</td><td>".$row["description"]."</td><td>".$row["due_date"]."</td><td>".$row["time"]."</td><td><button><a
href='delete.php?table=todotask&did=".$row["id"]."'>Delete</a></button></td>"."<td><button><a
href='checkcomplete.php?table=todotask&did=".$row["id"]."'>Complete</a></button></td>"."<td><button><a
href='modify.php?table=todotask&did=".$row["id"]."'>Modify</a></button></td>"."</td></tr>";
}
}
$displayQueryComplete="SELECT * FROM complete where owner=:owner";
$displayTaskComplete= $conn->prepare($displayQueryComplete);
$displayTaskComplete->bindValue(':owner', $owner);
$displayTaskComplete->execute();
$allTaskComplete= $displayTaskComplete->fetchAll();
echo "<table class=\"complete_table\"><caption>Completed Tasks</caption><tr><th>ID</th><th>Title</th><th>Description</th><th>Due Date</th><th>Time</th><th colspan='3'>Button</th></tr>";
if(count($allTaskComplete) > 0)
{
foreach ($allTaskComplete as $row) {
echo "<tr><td>".$row["id"]."</td><td>".$row["title"]."</td><td>".$row["description"]."</td><td>".$row["due_date"]."</td><td>".$row["time"]."</td><td><button><a
href='delete.php?table=completedtask&did=".$row["id"]."'>Delete</a></button></td>"."<td><button><a
href='checkcomplete.php?table=completedtask&did=".$row["id"]."'>Complete</a></button></td>"."<td><button><a
href='modify.php?table=completedtask&did=".$row["id"]."'>Modify</a></button></td>"."</td></tr>";
}
}
CSS:
.complete_table{
border: 4px solid #5e001f;
border-collapse: collapse;
position: absolute;
top: 34%;
right: 1%;
width: 600px;
max-width: 600px;
}
.complete_table caption, .incomplete_table caption{
font-size: 17px;
color: #5e001f;
font-weight: bold;
border: 1px solid #5e001f;
border-radius: 7px;
padding: 7px;
background-color: white;
margin: 7px;
}
.complete_table th{
border: 1px solid #5e001f;
color: #5e001f;
padding: 7px;
}
.complete_table td{
border: 1px solid #5e001f;
padding: 7px;
color: #5e001f;
}
.incomplete_table{
border: 4px solid #5e001f;
border-collapse: collapse;
position: absolute;
top: 34%;
left: 1%;
width: 600px;
max-width: 600px;
}
.incomplete_table th{
border: 1px solid #5e001f;
color: #5e001f;
padding: 7px;
}
.incomplete_table td{
border: 1px solid #5e001f;
padding: 7px;
color: #5e001f;
}
.incomplete_table a, .complete_table a{
text-decoration: none;
color: #5e001f;
}
.incomplete_table button, .complete_table button{
width: 76px;
background-color: white;
font-size: 14px;
font-weight: bold;
border: 1px solid #5e001f;
border-radius: 7px;
}
try this:
$displayQuery="SELECT * FROM incomplete where owner=:owner";
$displayTask= $conn->prepare($displayQuery);
$displayTask->bindValue(':owner', $owner);
$displayTask->execute();
$allTask=$displayTask->fetchAll();
echo "<table class=\"incomplete_table\"><caption>To-do Tasks</caption><tr><th>ID</th><th>Title</th><th>Description</th><th>Due Date</th><th>Time</th><th colspan='3'>Button</th></tr>";
if(count($allTask) > 0)
{
foreach ($allTask as $row) {
echo "<tr><td>".$row["id"]."</td><td>".$row["title"]."</td><td>".$row["description"]."</td><td>".$row["due_date"]."</td><td>".$row["time"]."</td><td><button><a
href='delete.php?table=todotask&did=".$row["id"]."'>Delete</a></button></td>"."<td><button><a
href='checkcomplete.php?table=todotask&did=".$row["id"]."'>Complete</a></button></td>"."<td><button><a
href='modify.php?table=todotask&did=".$row["id"]."'>Modify</a></button></td>"."</td></tr>";
}
}
echo "</table>";
$displayQueryComplete="SELECT * FROM complete where owner=:owner";
$displayTaskComplete= $conn->prepare($displayQueryComplete);
$displayTaskComplete->bindValue(':owner', $owner);
$displayTaskComplete->execute();
$allTaskComplete= $displayTaskComplete->fetchAll();
echo "<table class=\"complete_table\"><caption>Completed Tasks</caption><tr><th>ID</th><th>Title</th><th>Description</th><th>Due Date</th><th>Time</th><th colspan='3'>Button</th></tr>";
if(count($allTaskComplete) > 0)
{
foreach ($allTaskComplete as $row) {
echo "<tr><td>".$row["id"]."</td><td>".$row["title"]."</td><td>".$row["description"]."</td><td>".$row["due_date"]."</td><td>".$row["time"]."</td><td><button><a
href='delete.php?table=completedtask&did=".$row["id"]."'>Delete</a></button></td>"."<td><button><a
href='checkcomplete.php?table=completedtask&did=".$row["id"]."'>Complete</a></button></td>"."<td><button><a
href='modify.php?table=completedtask&did=".$row["id"]."'>Modify</a></button></td>"."</td></tr>";
}
}
echo "</table>";
This is my code for a project I am working on, is there anyway to shorten this code or even put it in a function so it is not this much repetitive code. I'm learning programming, and I was unable to find a solution to fix it. Is it a while loop or something I am meant to use?
$sth=$conn->prepare("SELECT * FROM players WHERE pid = {$steamprofile['steamid']}");
$sth->execute();
$result = $sth->fetch();
if($result['rank'] == 11){
echo "<button style='background-color: #ad0521; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Godfather</button>";
}
if($result['rank'] == 10){
echo "<button style='background-color: #999900; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Mob Boss</button>";
}
if($result['rank'] == 9){
echo "<button style='background-color: #798488; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Under Boss</button>";
}
if($result['rank'] == 8){
echo "<button style='background-color: #397be5; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Warlord</button>";
}
if($result['rank'] == 7){
echo "<button style='background-color: #6f9de8; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Turf Captain</button>";
}
if($result['rank'] == 6){
echo "<button style='background-color: #c1722c; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Hitman</button>";
}
if($result['rank'] == 5){
echo "<button style='background-color: #ffbf00; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Henchman</button>";
}
if($result['rank'] == 4){
echo "<button style='background-color: #008c5f; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Loan Shark</button>";
}
if($result['rank'] == 3){
echo "<button style='background-color: #12c98c; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Enforcer</button>";
}
if($result['rank'] == 2){
echo "<button style='background-color: #6a0e91; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Butcher</button>";
}
if($result['rank'] == 1){
echo "<button style='background-color: #b94ae8; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Scout</button>";
}
if($result['rank'] == 0){
echo "<button style='background-color: #595959; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Guest</button>";
}
You can have an array which holds the various attributes for each rank (I've used only colour and the label), then just use these in the one echo statement...
$rankTypes = [ 0 => ["color" => "#595959", "name" => "Guest"],
1 => ["color" => "#b94ae8", "name" => "Scout"]
];
echo "<button style='background-color: {$rankTypes[$result['rank']]['color']}; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>{$rankTypes[$result['rank']]['name']}</button>";
You keep on adding the extra rank types into the array.
I have two rows in my table that have random gaps beneath them. I have tried looking at colspans and messing around for ages, but they just don't seem to go. I have 3 <th>'s as you can see, and tried to align the rest of the table with this. The table is complete, and looks okay except for the blank lines beneath the rows with "timeleft" and "reward".
<table class="tabelle separate">
<tr>
<th>Jail</th><th></th><th></th>
</tr>
<tr>
<td width="40%"><div class="zelle"><center><b>Inmate</div></td>
<td width="25%"><div class="zelle"><center><b>Time left</div></td>
<td width="35%"><div class="zelle"><center><b>Reward</div></td>
</tr>
<?php
//desplay data
$get = mysql_query("SELECT * FROM jail");
while($row = mysql_fetch_assoc($get))
{
//get data
$id = $row['id'];
$name = ucwords($row['username']);
$timeleft = $row['time'] - time();
$reward = number_format($row['reward']);
$jailedcountry = $row['country'];
if($country === $jailedcountry){
echo "
<tr>
<td width=40%><div class='zelle'>
<form action='jail.php' method='post'>
<input name='bustid' type='radio' class='radio' value='$id'><a href='viewprofile.php?viewuser=$name'>
$name</a></div></td>
<td width=25%><div class='zelle'>$timeleft
</div></td>
<td width=35%><div class='zelle'>
$$reward</div></td>
</tr>
";
}
echo "
<tr><br><br>
<td align='center' colspan='3'><div class='zelle'>
<center> <input type='submit' name='bust' class='tbox' value='Bust User'> <Br>
</div>
</td>
</tr>
</form>
";
}
?>
<tr><td colspan="3"><div class="zelle">
<form action='jail.php' method='post'><center><input type='submit' name='pointsleave' class='tbox' value='Leave Jail (Costs 2 points)'> </center></form>
</div></td></tr>
</table>
CSS
.tabelle {
width: 50%; border-collapse: collapse; margin: auto; border-right: 1px solid Black;
}
.zelle{
padding: 1px;
background-color: #202020;
font-family: Arial;
font-size: 12px;
text-align: center;
color: white;
}
th {
background: #696969;
background-image: -webkit-linear-gradient(top, #696969, #393b3d);
background-image: -moz-linear-gradient(top, #696969, #393b3d);
background-image: -ms-linear-gradient(top, #696969, #393b3d);
background-image: -o-linear-gradient(top, #696969, #393b3d);
background-image: linear-gradient(to bottom, #696969, #393b3d);
padding: 6px;
color: White;
font-size: 14px;
font-family: Arial;
}
.separate {
border-radius: 3px;
border-spacing: 0;
border-collapse: separate;
}
.separate tr:last-child td:first-child {
border-bottom-left-radius: 3px;
}
.separate tr:last-child td:last-child {
border-bottom-right-radius: 3px;
}
.separate tr th:first-child, table.separate tr td:first-child {
border-left: 1px solid Black;
}
.separate tr:first-child th, table.separate tr:first-child td {
border-top: 1px solid Black;
}
.separate tr:first-child th:first-child, table.separate tr:first-child td:first-child {
border-top-left-radius: 3px
}
.separate tr:first-child th:last-child, table.separate tr:first-child td:last-child {
border-top-right-radius: 3px;
}
I have the below Table with HTML when i click the button(update) in the table row , the particular row values i.e the button belongs to which row the respected row values only insert or update in a table.
<script type = "text/javascript" >
var table = document.getElementsByTagName("table")[0];
var tbody = table.getElementsByTagName("tbody")[0];
tbody.onclick = function (e) {
e = e || window.event;
var data = [];
var target = e.srcElement || e.target;
while (target && target.nodeName !== "TR") {
target = target.parentNode;
}
if (target) {
var cells = target.getElementsByTagName("td");
for (var i = 0; i < cells.length; i++) {
data.push(cells[i].innerHTML);
}
}
alert(data);
};
</script>
<script type = "text/javascript" >
history.pushState(null, null, 'new2.html');
window.addEventListener('popstate', function(event) {
history.pushState(null, null, 'new2.html');
});
</script>
<style>
<script>
$(function() {
var pickers = {};
$('table tr').editable({
dropdowns: {
Aex: ['Automation', 'Manual']
},
edit: function(values) {
$(".edit i", this)
.removeClass('fa-pencil')
.addClass('fa-save')
.attr('title', 'Save');
pickers[this] = new Pikaday({
field: $("td[data-field=birthday] input", this)[0],
format: 'MMM D, YYYY'
});
},
save: function(values) {
$(".edit i", this)
.removeClass('fa-save')
.addClass('fa-pencil')
.attr('title', 'Edit');
if (this in pickers) {
pickers[this].destroy();
delete pickers[this];
}
},
cancel: function(values) {
$(".edit i", this)
.removeClass('fa-save')
.addClass('fa-pencil')
.attr('title', 'Edit');
if (this in pickers) {
pickers[this].destroy();
delete pickers[this];
}
}
});
});
</script><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-36251023-1']);
_gaq.push(['_setDomainName', 'jqueryscript.net']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
body {
margin-bottom: 100px;
}
.row {
margin-bottom: 20px;
}
pre {
margin-top: 0;
}
.button.button-small {
height: 30px;
line-height: 30px;
padding: 0px 10px;
}
td input[type=text], td select {
width: 100%;
height: 30px;
margin: 0;
padding: 2px 8px;
}
th:last-child {
text-align: right;
}
td:last-child {
text-align: right;
}
td:last-child .button {
width: 30px;
height: 30px;
text-align: center;
padding: 0px;
margin-bottom: 0px;
margin-right: 5px;
background-color: #FFF;
}
td:last-child .button .fa {
line-height: 30px;
width: 30px;
}
body {
font: 400 15px Lato, sans-serif;
line-height: 1.8;
color: #818181;
}
h2 {
font-size: 24px;
text-transform: uppercase;
color: #303030;
font-weight: 600;
margin-bottom: 30px;
}
h4 {
font-size: 19px;
line-height: 1.375em;
color: #303030;
font-weight: 400;
margin-bottom: 30px;
}
.jumbotron {
color: #fff;
padding: 100px 55px;
font-family: Montserrat, sans-serif;
height:500px;
background-image: url(header.jpg);
background-repeat:no-repeat;
background-attachment: fixed;
background-position: center;
}
.container-fluid {
padding: 60px 50px;
}
.bg-grey {
background-color: #f6f6f6;
}
.logo-small {
color: #0099ff;
font-size: 50px;
}
.logo-small1 {
color: #0099ff;
font-size: 20px;
}
.logo {
color: #0099ff;
font-size: 200px;
}
.thumbnail {
padding: 0 0 15px 0;
border: none;
border-radius: 0;
}
.thumbnail img {
width: 100%;
height: 100%;
margin-bottom: 10px;
}
#section {
width:350px;
padding:10px;
}
.carousel-control.right, .carousel-control.left {
background-image: none;
color: #39ac73;
}
.carousel-indicators li {
border-color: #39ac73;
}
.carousel-indicators li.active {
background-color: #39ac73;
}
.item h4 {
font-size: 19px;
line-height: 1.375em;
font-weight: 400;
font-style: italic;
margin: 70px 0;
}
.item span {
font-style: normal;
}
.panel {
border: 1px solid #39ac73;
border-radius:0 !important;
transition: box-shadow 0.5s;
}
.panel:hover {
box-shadow: 5px 0px 40px rgba(0,0,0, .2);
}
.panel-footer .btn:hover {
border: 1px solid #39ac73;
background-color: #fff !important;
color: #39ac73;
}
.panel-heading {
color: #fff !important;
background-color: #39ac73 !important;
padding: 25px;
border-bottom: 1px solid transparent;
border-top-left-radius: 0px;
border-top-right-radius: 0px;
border-bottom-left-radius: 0px;
border-bottom-right-radius: 0px;
}
.panel-footer {
background-color: white !important;
}
.panel-footer h3 {
font-size: 32px;
}
.panel-footer h4 {
color: #aaa;
font-size: 14px;
}
.panel-footer .btn {
margin: 15px 0;
background-color: #39ac73;
color: #fff;
}
.navbar {
margin-bottom: 0;
background-color: #fff;
z-index: 9999;
border: 0;
font-size: 12px !important;
line-height: 1.42857143 !important;
letter-spacing: 4px;
border-radius: 0;
font-family: Montserrat, sans-serif;
min-height: 70px;
}
.navbar li a, .navbar .navbar-brand {
color: #39ac73 !important;
}
.navbar-nav li a:hover, .navbar-nav li.active a {
color: #39ac73 !important;
background-color: #e5fff7 !important;
}
.navbar-default .navbar-toggle {
border-color: transparent;
color: #fff !important;
}
footer .glyphicon {
font-size: 20px;
margin-bottom: 20px;
color: #39ac73;
}
.slideanim {visibility:hidden;}
.slide {
animation-name: slide;
-webkit-animation-name: slide;
animation-duration: 1s;
-webkit-animation-duration: 1s;
visibility: visible;
}
#keyframes slide {
0% {
opacity: 0;
-webkit-transform: translateY(70%);
}
100% {
opacity: 1;
-webkit-transform: translateY(0%);
}
}
#-webkit-keyframes slide {
0% {
opacity: 0;
-webkit-transform: translateY(70%);
}
100% {
opacity: 1;
-webkit-transform: translateY(0%);
}
}
#media screen and (max-width: 768px) {
.col-sm-4 {
text-align: center;
margin: 25px 0;
}
.btn-lg {
width: 100%;
margin-bottom: 35px;
}
}
#media screen and (max-width: 480px) {
.logo {
font-size: 150px;
}
}
<html lang="en">
<head>
<meta charset="utf-8">
<title>Windows</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="http://fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
<link href="http://code.jquery.com/jquery-1.11.3.min.js" >
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="css/pikaday.css" >
<link rel="stylesheet" href="css/pikaday-skeleton.css" >
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link href="http://www.jqueryscript.net/css/jquerysctipttop.css" rel="stylesheet" type="text/css">
</head>
<body id="myPage" data-spy="scroll" data-target=".navbar" data-offset="60">
<div class="container-fluid text-center">
<h1>Windows Data</h1>
<table id="tab_logic" class="table">
<thead >
<tr class="info">
<th>S.No</th>
<th>Machine Name</th>
<th>IP</th>
<th>Host name</th>
<th>Tester Name</th>
<th>Installation Plan</th>
<th>OS Version</th>
<th>MI Version</th>
<th>AUT/MAT</th>
<th>Reimage</th>
<th>Edit</th>
<th>Update</th>
<th>Mail</th>
</tr>
</thead>
<tbody>
<tr id='addr0' data-id="1">
<td id="sn" data-field="S.No">1</td>
<td data-field="Machine Name">sxsxsdsd</td>
<td data-field="IP">sssss</td>
<td data-field="Host name">zxzxzx</td>
<td data-field="Tester Name">Unassigned</td>
<td data-field="Installation Plan">Null</td>
<td data-field="OS Version">Windows 8.1 Pro</td>
<td data-field="MI Version">Null</td>
<td data-field="Aex">Manual</td>
<td data-field="Reimage">21/7/2015</td>
<td><a class="button button-small edit" title="Edit"><i class="fa fa-pencil"></i></a></td>
<td><button type="submit" onclick="one()" class="btn btn-primary"><span class="glyphicon glyphicon-folder-open"></span></button></td>
<td ><button type="submit" class="btn btn-info"><span class="glyphicon glyphicon-send"></span></button></td>
</tr>
<tr data-id="2">
<td data-field="S.No">2</td>
<td data-field="Machine Name">sdsdsdsd</td>
<td data-field="IP">dsdsdsdsd</td>
<td data-field="Host name">sdsdsdsdsd</td>
<td data-field="Tester Name">dsdsdsdsd</td>
<td data-field="Installation Plan">[ For OLS ] MI PC offline</td>
<td data-field="OS Version">Windows 8.1 Pro</td>
<td data-field="MI Version">Null</td>
<td data-field="Aex">Manual</td>
<td data-field="Reimage">21/7/2015</td>
<td>
<a class="button button-small edit" title="Edit">
<i class="fa fa-pencil"></i>
</a>
</td>
<td><button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-folder-open"></span></button></td>
<td><button type="submit" class="btn btn-info"><span class="glyphicon glyphicon-send"></span></button></td>
</tr>
<tr data-id="3">
<td data-field="S.No">3</td>
<td data-field="Machine Name">sdsdsdsd</td>
<td data-field="IP">dsdsdsd</td>
<td data-field="Host name">sdsdsdsd</td>
<td data-field="Tester Name">Unassigned</td>
<td data-field="Installation Plan">Null</td>
<td data-field="OS Version">Windows 8.1 Pro</td>
<td data-field="MI Version">Null</td>
<td data-field="Aex">Manual</td>
<td data-field="Reimage">21/7/2015</td>
<td>
<a class="button button-small edit" title="Edit">
<i class="fa fa-pencil"></i>
</a>
</td>
<td><button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-folder-open"></span></button></td>
<td><button type="submit" class="btn btn-info"><span class="glyphicon glyphicon-send"></span></button></td>
</tr>
</tbody>
</table>
</div>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
<script src="Pikaday/pikaday.js"></script>
<script src="build/table-edits.min.js"></script>
</body>
</html>
Use for loop to display html table, and use index in the button.
For example, if you want to delete a meeting from the table by clicking delete button next to it, then you can do something like this:
Example format
meeting1 DELETE(button)
meeting2 DELETE(button)
meeting3 DELETE(button)
The delete button will be same only the url will be changing.
echo "<tr>
<th>Status</th>
<th>Title</th>
<th>Scheduled By</th>
<th>Scheduled Date</th>
<th>Start Time</th>
<th>End Time</th>
<th>Actions</th>
</tr>";
for ($n = 0; $n < count($meeting_array); $n++) {
$meetingname = $meeting_array[$n]; //contains meeting names.
echo "<td style= \"color : darkgoldenrod; text : strong;\" >" . $status . "</td>";
echo "<td>" . $meetingname2 . "</td>";
echo "<td>" . $extractedname . "</td>";
echo "<td>" . $mydate . "</td>";
echo "<td>" . $mystarttime . "</td>";
echo "<td>" . $myendtime . "</td>";
echo"<td>";
// pass meeting name in url.
echo"<a href=\"View_Meeting.php?id={$meetingname}\" <img src=\"../img/read1.png\" alt=\"Read\" /> ";
echo "</td>";
}
echo "</tr>";