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;
}
I have a script that checks for dupe values in db and loops through the result and echoes the value using json. However, it is only displaying 1 record instead of 3 which is being sent to php. I would be grateful if someone could point out my error. Thanks
$boxitems = mysqli_real_escape_string($conn, $_POST['box']);
$array = array();
$array = $boxitems;
foreach ($array as $boxes) {
$sql = "SELECT item FROM act WHERE item = '".$boxes."' GROUP BY item HAVING COUNT(*) > 1";
$result = mysqli_query($conn, $sql) or die('Error selecting item: ' . mysqli_error());
$num_rows = mysqli_num_rows($result);
if($num_rows) {
while ($row = mysqli_fetch_array($result)) {
$data[] = $row['item'];
}
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: red; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo json_encode($data) . ' already exists. Please enter a unique box reference.';
echo '</div>';
exit;
} else {
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: #63c84c; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo 'No dupes found in database.';
echo '</div>';
exit;
}
}
UPDATED screen shot
Put what your want to echo into a single variable that is declared outside the foreach and concatenate each div (one for each loop your foreach does). And then echo it after the loop.
$boxitems = $_POST['box'];
$insertedItems = array();
$duplicateItems = array();
foreach ($boxitems as $boxes) {
$escapedBoxes = mysqli_real_escape_string($conn, $boxes);
$sql = "SELECT item FROM act WHERE item = '".$escapedBoxes."' GROUP BY item HAVING COUNT(*) > 0";
$result = mysqli_query($conn, $sql) or die('Error selecting item: ' . mysqli_error());
$num_rows = mysqli_num_rows($result);
if($num_rows) {
while ($row = mysqli_fetch_array($result)) {
$duplicateItems[] = $row['item'];
}
}
else
{
$insertedItems[] = $escapedBoxes;
}
}
if(!empty($duplicateItems)) {
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: red; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo json_encode($duplicateItems) . ' already exists. Please enter a unique box reference.';
echo '</div>';
} else {
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: #63c84c; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo 'No dupes found in database.<br/>';
echo json_encode($insertedItems) . ' has been entered successfully into the database.';
echo '</div>';
}
EDIT: Updated code considering u_mulder comment.
$boxitems = mysqli_real_escape_string($conn, $_POST['box']);
$array = array();
$array = $boxitems;
foreach ($array as $boxes) {
$sql = "SELECT item FROM act WHERE item = '".$boxes."' GROUP BY item HAVING COUNT(*) > 1";
$result = mysqli_query($conn, $sql) or die('Error selecting item: ' . mysqli_error());
$num_rows = mysqli_num_rows($result);
if($num_rows) {
while ($row = mysqli_fetch_array($result)) {
$data[] = $row['item'];
}
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: red; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo json_encode($data) . ' already exists. Please enter a unique box reference.';
echo '</div>';
exit;
} else {
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: #63c84c; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo 'No dupes found in database.';
echo '</div>';
}
exit;
}
An exit inside any function, loop or condition will make the program to go out of it and continue, so it's not iterating through, it's exiting after the first iteration.
Hi there I have two forms that display results based on user inputed data (php/database query) into tabular format. My problem is that both of the forms are positioned on the left hand side of the page and when i run the second form it places the table in the position where the the first query should be. I would like the second form to be placed to the right hand side of the page so that the first form table displays on the left hand side of the page and the second form table displays on the right hand side of the page. I have used methods like "align=right" but this hasnt worked. Any idea on how i can achieve this. Here is my code.
$table .= '<tr>';
$table .= '<td><strong><font color="#000000">ID</font></strong></td>';
$table .= '<td><strong><font color="#000000">Name</font></strong></td>';
$table .= '<td><strong><font color="#000000">Contact</font></strong></td>';
$table .= '<td><strong><font color="#000000">Start Date</font></strong></td>';
$table .= '<td><strong><font color="#000000">End Date</font></strong></td>';
$table .= '<td><strong><font color="#000000">Facility ID</font></strong></td>';
$table .= '</tr>';
foreach ($events as $event) {
$table .= '<tr>';
$table .= '<td>' . $event['id'] . '</td>';
$table .= '<td>' . $event['name'] . '</td>';
$table .= '<td>' . $event['contact'] . '</td>';
$table .= '<td>' . $event['start'] . '</td>';
$table .= '<td>' . $event['end'] . '</td>';
$table .= '<td>' . $event['resource_id'] . '</td>';
$table .= '</tr>';
}
$table .= '</table>';
echo $table;
}
}
?>
<form method="POST">
Start DATE: <input type="text" name="start" /><br />
End DATE: <input type="text" name="end" />
<input type="submit" name="submit" />
</form>
<form method="POST">
<h3 style="font-family:verdana;"> <u>Search a name</u></h3>
Name: <input type="text" name="name" /><br />
<input type="submit" name="submit" />
</form>
Wrap the two forms in a div
<div class="forms">
<form></form>
<form></form>
</div>
Use the flex property
.forms{
display:flex;
justify-content: space-between;
flex-wrap: wrap
}
For more information on flexbox, visit https://flexbox.io/ or https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox
I think, what you need is css... try using Skeleton or bootstrap.
Also you have to Echo the result of the php code below the forms.
if you use Skeleton you might have something like this:
/*
* Skeleton V2.0.4
* Copyright 2014, Dave Gamache
* www.getskeleton.com
* Free to use under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
* 12/29/2014
*/
/* Table of contents
––––––––––––––––––––––––––––––––––––––––––––––––––
- Grid
- Base Styles
- Typography
- Links
- Buttons
- Forms
- Lists
- Code
- Tables
- Spacing
- Utilities
- Clearing
- Media Queries
*/
/* Grid
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.container {
position: relative;
width: 100%;
max-width: 960px;
margin: 0 auto;
padding: 0 20px;
box-sizing: border-box; }
.column,
.columns {
width: 100%;
float: left;
box-sizing: border-box; }
/* For devices larger than 400px */
#media (min-width: 400px) {
.container {
width: 85%;
padding: 0; }
}
/* For devices larger than 550px */
#media (min-width: 550px) {
.container {
width: 80%; }
.column,
.columns {
margin-left: 4%; }
.column:first-child,
.columns:first-child {
margin-left: 0; }
.one.column,
.one.columns { width: 4.66666666667%; }
.two.columns { width: 13.3333333333%; }
.three.columns { width: 22%; }
.four.columns { width: 30.6666666667%; }
.five.columns { width: 39.3333333333%; }
.six.columns { width: 48%; }
.seven.columns { width: 56.6666666667%; }
.eight.columns { width: 65.3333333333%; }
.nine.columns { width: 74.0%; }
.ten.columns { width: 82.6666666667%; }
.eleven.columns { width: 91.3333333333%; }
.twelve.columns { width: 100%; margin-left: 0; }
.one-third.column { width: 30.6666666667%; }
.two-thirds.column { width: 65.3333333333%; }
.one-half.column { width: 48%; }
/* Offsets */
.offset-by-one.column,
.offset-by-one.columns { margin-left: 8.66666666667%; }
.offset-by-two.column,
.offset-by-two.columns { margin-left: 17.3333333333%; }
.offset-by-three.column,
.offset-by-three.columns { margin-left: 26%; }
.offset-by-four.column,
.offset-by-four.columns { margin-left: 34.6666666667%; }
.offset-by-five.column,
.offset-by-five.columns { margin-left: 43.3333333333%; }
.offset-by-six.column,
.offset-by-six.columns { margin-left: 52%; }
.offset-by-seven.column,
.offset-by-seven.columns { margin-left: 60.6666666667%; }
.offset-by-eight.column,
.offset-by-eight.columns { margin-left: 69.3333333333%; }
.offset-by-nine.column,
.offset-by-nine.columns { margin-left: 78.0%; }
.offset-by-ten.column,
.offset-by-ten.columns { margin-left: 86.6666666667%; }
.offset-by-eleven.column,
.offset-by-eleven.columns { margin-left: 95.3333333333%; }
.offset-by-one-third.column,
.offset-by-one-third.columns { margin-left: 34.6666666667%; }
.offset-by-two-thirds.column,
.offset-by-two-thirds.columns { margin-left: 69.3333333333%; }
.offset-by-one-half.column,
.offset-by-one-half.columns { margin-left: 52%; }
}
/* Base Styles
–––––––––––––––––––––––––––––––––––––––––––––––––– */
/* NOTE
html is set to 62.5% so that all the REM measurements throughout Skeleton
are based on 10px sizing. So basically 1.5rem = 15px :) */
html {
font-size: 62.5%; }
body {
font-size: 1.5em; /* currently ems cause chrome bug misinterpreting rems on body element */
line-height: 1.6;
font-weight: 400;
font-family: "Raleway", "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #222; }
/* Typography
–––––––––––––––––––––––––––––––––––––––––––––––––– */
h1, h2, h3, h4, h5, h6 {
margin-top: 0;
margin-bottom: 2rem;
font-weight: 300; }
h1 { font-size: 4.0rem; line-height: 1.2; letter-spacing: -.1rem;}
h2 { font-size: 3.6rem; line-height: 1.25; letter-spacing: -.1rem; }
h3 { font-size: 3.0rem; line-height: 1.3; letter-spacing: -.1rem; }
h4 { font-size: 2.4rem; line-height: 1.35; letter-spacing: -.08rem; }
h5 { font-size: 1.8rem; line-height: 1.5; letter-spacing: -.05rem; }
h6 { font-size: 1.5rem; line-height: 1.6; letter-spacing: 0; }
/* Larger than phablet */
#media (min-width: 550px) {
h1 { font-size: 5.0rem; }
h2 { font-size: 4.2rem; }
h3 { font-size: 3.6rem; }
h4 { font-size: 3.0rem; }
h5 { font-size: 2.4rem; }
h6 { font-size: 1.5rem; }
}
p {
margin-top: 0; }
/* Links
–––––––––––––––––––––––––––––––––––––––––––––––––– */
a {
color: #1EAEDB; }
a:hover {
color: #0FA0CE; }
/* Buttons
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.button,
button,
input[type="submit"],
input[type="reset"],
input[type="button"] {
display: inline-block;
height: 38px;
padding: 0 30px;
color: #555;
text-align: center;
font-size: 11px;
font-weight: 600;
line-height: 38px;
letter-spacing: .1rem;
text-transform: uppercase;
text-decoration: none;
white-space: nowrap;
background-color: transparent;
border-radius: 4px;
border: 1px solid #bbb;
cursor: pointer;
box-sizing: border-box; }
.button:hover,
button:hover,
input[type="submit"]:hover,
input[type="reset"]:hover,
input[type="button"]:hover,
.button:focus,
button:focus,
input[type="submit"]:focus,
input[type="reset"]:focus,
input[type="button"]:focus {
color: #333;
border-color: #888;
outline: 0; }
.button.button-primary,
button.button-primary,
input[type="submit"].button-primary,
input[type="reset"].button-primary,
input[type="button"].button-primary {
color: #FFF;
background-color: #33C3F0;
border-color: #33C3F0; }
.button.button-primary:hover,
button.button-primary:hover,
input[type="submit"].button-primary:hover,
input[type="reset"].button-primary:hover,
input[type="button"].button-primary:hover,
.button.button-primary:focus,
button.button-primary:focus,
input[type="submit"].button-primary:focus,
input[type="reset"].button-primary:focus,
input[type="button"].button-primary:focus {
color: #FFF;
background-color: #1EAEDB;
border-color: #1EAEDB; }
/* Forms
–––––––––––––––––––––––––––––––––––––––––––––––––– */
input[type="email"],
input[type="number"],
input[type="search"],
input[type="text"],
input[type="tel"],
input[type="url"],
input[type="password"],
textarea,
select {
height: 38px;
padding: 6px 10px; /* The 6px vertically centers text on FF, ignored by Webkit */
background-color: #fff;
border: 1px solid #D1D1D1;
border-radius: 4px;
box-shadow: none;
box-sizing: border-box; }
/* Removes awkward default styles on some inputs for iOS */
input[type="email"],
input[type="number"],
input[type="search"],
input[type="text"],
input[type="tel"],
input[type="url"],
input[type="password"],
textarea {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none; }
textarea {
min-height: 65px;
padding-top: 6px;
padding-bottom: 6px; }
input[type="email"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
input[type="text"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus {
border: 1px solid #33C3F0;
outline: 0; }
label,
legend {
display: block;
margin-bottom: .5rem;
font-weight: 600; }
fieldset {
padding: 0;
border-width: 0; }
input[type="checkbox"],
input[type="radio"] {
display: inline; }
label > .label-body {
display: inline-block;
margin-left: .5rem;
font-weight: normal; }
/* Lists
–––––––––––––––––––––––––––––––––––––––––––––––––– */
ul {
list-style: circle inside; }
ol {
list-style: decimal inside; }
ol, ul {
padding-left: 0;
margin-top: 0; }
ul ul,
ul ol,
ol ol,
ol ul {
margin: 1.5rem 0 1.5rem 3rem;
font-size: 90%; }
li {
margin-bottom: 1rem; }
/* Code
–––––––––––––––––––––––––––––––––––––––––––––––––– */
code {
padding: .2rem .5rem;
margin: 0 .2rem;
font-size: 90%;
white-space: nowrap;
background: #F1F1F1;
border: 1px solid #E1E1E1;
border-radius: 4px; }
pre > code {
display: block;
padding: 1rem 1.5rem;
white-space: pre; }
/* Tables
–––––––––––––––––––––––––––––––––––––––––––––––––– */
th,
td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid #E1E1E1; }
th:first-child,
td:first-child {
padding-left: 0; }
th:last-child,
td:last-child {
padding-right: 0; }
/* Spacing
–––––––––––––––––––––––––––––––––––––––––––––––––– */
button,
.button {
margin-bottom: 1rem; }
input,
textarea,
select,
fieldset {
margin-bottom: 1.5rem; }
pre,
blockquote,
dl,
figure,
table,
p,
ul,
ol,
form {
margin-bottom: 2.5rem; }
/* Utilities
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.u-full-width {
width: 100%;
box-sizing: border-box; }
.u-max-full-width {
max-width: 100%;
box-sizing: border-box; }
.u-pull-right {
float: right; }
.u-pull-left {
float: left; }
/* Misc
–––––––––––––––––––––––––––––––––––––––––––––––––– */
hr {
margin-top: 3rem;
margin-bottom: 3.5rem;
border-width: 0;
border-top: 1px solid #E1E1E1; }
/* Clearing
–––––––––––––––––––––––––––––––––––––––––––––––––– */
/* Self Clearing Goodness */
.container:after,
.row:after,
.u-cf {
content: "";
display: table;
clear: both; }
/* Media Queries
–––––––––––––––––––––––––––––––––––––––––––––––––– */
/*
Note: The best way to structure the use of media queries is to create the queries
near the relevant code. For example, if you wanted to change the styles for buttons
on small devices, paste the mobile query code up in the buttons section and style it
there.
*/
/* Larger than mobile */
#media (min-width: 400px) {}
/* Larger than phablet (also point when grid becomes active) */
#media (min-width: 550px) {}
/* Larger than tablet */
#media (min-width: 750px) {}
/* Larger than desktop */
#media (min-width: 1000px) {}
/* Larger than Desktop HD */
#media (min-width: 1200px) {}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<div class="container">
<div class="row">
<div class="six columns" >
<div class="row">
<div class="columns" >
<h4>Form 1</h4>
<hr/>
<form method="POST">
Start DATE: <input type="text" name="start" /><br />
End DATE: <input type="text" name="end" /><br />
<input type="submit" name="submit" />
</form>
</div>
</div>
</div>
<div class="six columns" >
<div class="row">
<div class="columns" >
<h4>Form 2</h4>
<hr/>
<form method="POST">
<h3 style="font-family:verdana;"> <u>Search a name</u></h3>
Name: <input type="text" name="name" /><br />
<input type="submit" name="submit" />
</form>
</div>
</div>
</div>
</div>
<div class="row">
<div class="twelve columns" >
<div class="row">
<div class="columns" >
<h4>My result</h4>
<hr/>
<!-- Php Code here -->
Php Code here
</div>
</div>
</div>
</div>
</div>
</body>
</html>
I want to apply filter to my html table for following:
1. Search name/emailid
2. Page Length (As my table has thousands of records)
Also, I want to give an option to update record where I enter name, all information should be autopopulated to that form and then user can update whatever he wants to.
Following is my code given:
<?php
$db_host = 'localhost'; // Server Name
$db_user = 'root'; // Username
$db_pass = ''; // Password
$db_name = 'contacts'; // Database Name
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$conn) {
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
$sql = 'SELECT *
FROM usait LIMIT 50' ;
$query = mysqli_query($conn, $sql);
if (!$query) {
die ('SQL Error: ' . mysqli_error($conn));
}
?>
<html>
<head>
<title>Displaying MySQL Data in HTML Table</title>
<style type="text/css">
<link rel="stylesheet" href="http://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css">
<script src="http://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
body { {
font-size: 15px;
color: #343d44;
font-family: "segoe-ui", "open-sans", tahoma, arial;
padding: 0;
margin: 0;
}
table {
margin: auto;
font-family: "Lucida Sans Unicode", "Lucida Grande", "Segoe Ui";
font-size: 12px;
}
h1 {
margin: 25px auto 0;
text-align: center;
text-transform: uppercase;
font-size: 17px;
}
table td {
transition: all .5s;
}
/* Table */
.data-table {
border-collapse: collapse;
font-size: 14px;
min-width: 537px;
}
.data-table th,
.data-table td {
border: 1px solid #e1edff;
padding: 7px 17px;
}
.data-table caption {
margin: 7px;
}
/* Table Header */
.data-table thead th {
background-color: #508abb;
color: #FFFFFF;
border-color: #6ea1cc !important;
text-transform: uppercase;
}
/* Table Body */
.data-table tbody td {
color: #353535;
}
.data-table tbody td:first-child,
.data-table tbody td:nth-child(4),
.data-table tbody td:last-child {
text-align: right;
}
.data-table tbody tr:nth-child(odd) td {
background-color: #f4fbff;
}
.data-table tbody tr:hover td {
background-color: #ffffa2;
border-color: #ffff0f;
}
/* Table Footer */
.data-table tfoot th {
background-color: #e5f5ff;
text-align: right;
}
.data-table tfoot th:first-child {
text-align: left;
}
.data-table tbody td:empty
{
background-color: #ffcccc;
}
</style>
</head>
<body>
<table class="data-table" id="example">
<caption class="title">US Data</caption>
<thead>
<tr>
<th>id</th>
<th>ContactOwner</th>
<th>LeadSource</th>
<th>First_name</th>
<th>Last_name</th>
<th>AccountName</th>
<th>Title</th>
<th>EmailID</th>
<th>Department</th>
<th>Industry</th>
<th>Phone</th>
<th>Mobile</th>
<th>Fax</th>
<th>DOB</th>
<th>Assistant</th>
<th>AsstPhone</th>
<th>ReportsTo</th>
<th>LinkedIn</th>
<th>CallStatus</th>
<th>Street</th>
<th>OtherStreet</th>
<th>City</th>
<th>State</th>
<th>Zip</th>
<th>Country</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<?php
$no = 1;
$total = 0;
while ($row = mysqli_fetch_array($query))
{
echo '<tr>
<td>'.$row['id'].'</td>
<td>'.$row['ContactOwner'].'</td>
<td>'.$row['LeadSource'].'</td>
<td>'.$row['First_name'].'</td>
<td>'.$row['Last_name'].'</td>
<td>'.$row['AccountName'].'</td>
<td>'.$row['Title'].'</td>
<td>'.$row['EmailID'].'</td>
<td>'.$row['Department'].'</td>
<td>'.$row['Industry'].'</td>
<td>'.$row['Phone'].'</td>
<td>'.$row['Mobile'].'</td>
<td>'.$row['Fax'].'</td>
<td>'.$row['DOB'].'</td>
<td>'.$row['Assistant'].'</td>
<td>'.$row['AsstPhone'].'</td>
<td>'.$row['ReportsTo'].'</td>
<td>'.$row['LinkedIn'].'</td>
<td>'.$row['CallStatus'].'</td>
<td>'.$row['Street'].'</td>
<td>'.$row['OtherStreet'].'</td>
<td>'.$row['City'].'</td>
<td>'.$row['State'].'</td>
<td>'.$row['Zip'].'</td>
<td>'.$row['Country'].'</td>
<td>'.$row['Description'].'</td>
</tr>';
$no++;
}?>
</tbody>
<tfoot>
<tr>
<th colspan="26">TOTAL</th>
<th><?=number_format($total)?></th>
</tr>
</tfoot>
</table>
<script>
$(document).ready(function() {
$('#example').DataTable( {
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, 100, "All"]]
} );
} );
</script>
</body>
</html>
Use server-side processing feature of DataTables instead of rendering inside HTML. With server-side processing able to handle large data sets. Also other features will be work like a charm filtering, searching, pagination etc. as you want.
DataTables provide simple example for this. Frontend and server-side scripts are both available, you have to just configure your MySQL connection and will be ready to go.
I Have a problem when I try to sort my table with tablesorter.js. It looks easy to use it, but in my case it doesn't work...
First of all, I explain my application:
1.- I have a database with several data
2.- I developed a web interface to search that data (HTML)
3.- I wanted to make interactive communication with the database, so I used AJAX
4.- I build the querys and the table with the results in another php file
So, in my HTML file:
<div id = "DivResults"></div>
And in the header of this file I added the jquery and tablesorter.js references and to my CSS file the contento of the CSS from tablesorter
$(document).ready(function() { $("#myTable").tablesorter(); } );
Now, in the php file I have the following code:
<table id="myTable" class="tablesorter" style="font-size: 8pt; position:relative; top: -10px;" >
<thead>
<tr>
<th><b>Col1</b></th>
<th><b>Col2</b></th>
<th><b>Col3</b></th>
<th><b>Col4</b></th>
<th><b>Col5</b></th>
</tr>
</thead>
<tbody>
<?php
for ($i = 0; $i<$n;$i++)
{
$Result_array = ordenar_array($Result_array,2, SORT_ASC,3,SORT_ASC);
echo "<tr>";
for ($aux = 0; $aux<5;$aux++)
{
echo "<td> ".$Result_array [$i][$aux]."</td>";
}
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
?>
The table it's ok, the data are also ok and I display it in the correct way, but can't sort it with this function. Could anyone help me?
EDIT: this is the code that I added to my CSS file:
/* tables */
table.tablesorter {
font-family:arial;
background-color: #CDCDCD;
margin:10px 0pt 15px;
font-size: 8pt;
width: 100%;
text-align: left;
}
table.tablesorter thead tr th, table.tablesorter tfoot tr th {
background-color: #e6EEEE;
border: 1px solid #FFF;
font-size: 8pt;
padding: 4px;
}
table.tablesorter thead tr .header {
background-image: url(../img/bg.gif);
background-repeat: no-repeat;
background-position: center right;
cursor: pointer;
}
table.tablesorter tbody td {
color: #3D3D3D;
padding: 4px;
background-color: #FFF;
vertical-align: top;
}
table.tablesorter tbody tr.odd td {
background-color:#F0F0F6;
}
table.tablesorter thead tr .headerSortUp {
background-image: url(../img/asc.gif);
}
table.tablesorter thead tr .headerSortDown {
background-image: url(../img/desc.gif);
}
table.tablesorter thead tr .headerSortDown, table.tablesorter thead tr .headerSortUp {
background-color: #8dbdd8;
}