we have created a table (6x2) with column 2 containing a FA circle followed by a database field (environment in the example below) which contains the value (Outstanding, Very Good, Good, Needs Improvement & Adequate).
I want the colour of the fa-circle (traffic light colours) to be set depending on the value of field that is in that line with an arbitrary map (the correspondence between color and value will be arbitrary and set upfront).
I'm both available to have it solved server side or client side but I wish the document to have that feature where each value in the second column will have a fa-circle with a color depending on that value.
</h2>
<table class="tableag" style="width: 80%;">
<tbody>
<tr>
<td style="width: 40.0000%;background-color: #ffffff;color: #f2a34f;border-top: 3px solid #ffffff;
border-left: 3px solid #ffffff;"><b>Category</b></td>
<td style="width: 60.0000%;background-color: #ffffff;color: #f2a34f;border-top: 3px solid #ffffff;
border-left: 3px solid #ffffff;"><b>Rating</b></td>
</tr>
<tr>
<td style="width: 40.0000%;">Overall<br></td>
<td style="width: 60.0000%;background-color: #ffffff;color: #000000; class = "outcome"; "><i class="fa fa-circle" aria-hidden="true"></i> <br><?php echo $user['rating']?></td>
</tr>
<tr>
<td style="width: 40.0000%;">Care & Support<br></td>
<td style="width: 60.0000%;background-color: #ffffff;color: #000000;class = "outcome";"> <i class="fa fa-circle" aria-hidden="true"></i> <br><?php echo $user['care_and_support']?></td>
</tr>
<tr>
<td style="width: 40.0000%;">Environment<br></td>
<td style="width: 60.0000%;background-color: #ffffff;color: #000000;class = "outcome";"><i class="fa fa-circle" aria-hidden="true"></i> <br><?php echo $user['environment']?></td>
</tr>
<tr>
<td style="width: 40.0000%;">Leadership<br></td>
<td style="width: 60.0000%;background-color: #ffffff;color: #000000;class = "outcome";"><i class="fa fa-circle" aria-hidden="true"></i> <br><?php echo $user['leadership']?></td>
</tr>
<tr>
<td style="width: 40.0000%;">Staff & team</td>
<td style="width: 60.0000%;background-color: #ffffff;color: #000000;class = "outcome";"><i class="fa fa-circle" aria-hidden="true"></i> <br><?php echo $user['staff_team']?></td>
</tr>
<tr>
<td style="width: 40.0000%;">Wellbeing<br></td>
<td style="width: 60.0000%;background-color: #ffffff;color: #000000;class = "outcome";"><i class="fa fa-circle" aria-hidden="true"></i> <br><?php echo $user['wellbeing']?></td>
</tr>
<tr>
<td style="width: 40.0000%;">Full report<br></td>
<td style="width: 60.0000%;background-color: #ffffff;color: #000000;"><a class="btn btn-warning btn-rg" href=<?php echo $user['cqc_url_report_english']?> target="_blank">Full Report</a></td>
</tr>
</tbody>
</table>
Assuming you want 5 different colors, I suggest you to use a custom PHP function within your script
<?php
function getColor($rank)
{
switch($rank)
{
case 'Outstanding': return 'green';
case 'Very Good' : return 'yellow';
case 'Good': return 'orange';
case 'Needs Improvement' : return 'red';
case 'Adequate' : return 'grey';
default : return 'black';
}
}
?>
<i class="fa fa-circle" aria-hidden="true" style="color:<?php getColor(rank)?>"></i>
For a more cleaner approch, you can return a CSS class name within your function instead of a color
This solution will use a javascript strategy that will run client side.
You have a map defining which css class corresponds to each ranking value as mapOfColors.
When the page will be loaded in the browser, the code will loop through all the table rows, looking for the value of each second column and changing color of the nested i.fa element assigning a css class to it corresponding to its text value.
I chose arbitrary colours for each (decided upfront) ranking value.
I also took the chance to better refactor the styling of your table so that it's defined as css rules.
const mapOfColors =
{
'0' : 'rank0',
'1' : 'rank1',
'2' : 'rank2',
'3' : 'rank3',
'4' : 'rank4',
'5' : 'rank5',
'6' : 'rank6',
/*...*/
}
const rows = document.querySelectorAll('.tableag tbody tr');
for(const row of rows){
const field = row.querySelector('td:nth-child(2)');
const value = field.textContent.trim();
if(mapOfColors.hasOwnProperty(value)){
const className = mapOfColors[value];
field.querySelector('i.fa').classList.add(className);
}
}
.tableag{
width: 80%;
}
/*style for the header first col*/
.tableag > thead > tr > th:nth-child(1){
width: 40%;
background-color: #ffffff;
color: #f2a34f;
border-top: 3px solid #ffffff;
border-left: 3px solid #ffffff;
text-align: left;
}
/*style for the header second col*/
.tableag > thead > tr > th:nth-child(2){
width: 60%;
background-color: #ffffff;
color: #f2a34f;
border-top: 3px solid #ffffff;
border-left: 3px solid #ffffff;
text-align: left;
}
/*style for the table content first col*/
.tableag > tbody > tr > td:nth-child(1){
width: 40%;
}
/*style for the table content second col*/
.tableag > tbody > tr > td:nth-child(2){
width: 60%;
background-color: #ffffff;
color: #000000;
}
/*Ranking styles*/
.rank0{ color: red; }
.rank1{ color: orange; }
.rank2{ color: green; }
.rank3{ color: blue; }
.rank4{ color: pink; }
.rank5{ color: black; }
.rank6{ color: gray; }
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<table class="tableag">
<thead>
<tr>
<th><b>Category</b></th>
<th><b>Rating</b></th>
</tr>
</thead>
<tbody>
<tr>
<td>Overall<br></td>
<td>
<i class="fa fa-circle" aria-hidden="true"></i>
1<br>
</td>
</tr>
<tr>
<td>Care & Support<br></td>
<td>
<i class="fa fa-circle" aria-hidden="true"></i>
2<br>
</td>
</tr>
<tr>
<td>Environment<br></td>
<td>
<i class="fa fa-circle" aria-hidden="true"></i>
3<br>
</td>
</tr>
<tr>
<td>Leadership<br></td>
<td>
<i class="fa fa-circle" aria-hidden="true"></i>
4<br>
</td>
</tr>
<tr>
<td>Staff & team</td>
<td>
<i class="fa fa-circle" aria-hidden="true"></i>
5<br>
</td>
</tr>
<tr>
<td>Wellbeing<br></td>
<td>
<i class="fa fa-circle" aria-hidden="true"></i>
6<br>
</td>
</tr>
<tr>
<td>Full report<br></td>
<td>
<a class="btn btn-warning btn-rg" href="" target="_blank">Full Report</a>
</td>
</tr>
</tbody>
</table>
Related
I have a HTML table where user can choose products from MySql db.
I have a "add new row" possibility where new row is added to DOM.
Once I add new row, select-2 is no longer functioning in this new row - I beleive it is a problem, that it is searching for input only in first example of select-2 dropdown. How can I show dropdown for each instance?
Code:
<table id="add_new" style="width: 100%; margin-top:40px;" class="col-12 col-lg-12 col-md-12 col-sm-12 col-xl-12">
<thead>
<tr>
<th style="text-align:left; font-size: 10px; color:#8f8f8f; padding-bottom: 15px; width: 10%;">
Zap. št.: </th>
<th style="text-align:left; font-size: 10px; color:#8f8f8f; padding-bottom: 15px; width: 50%;">
Naziv artikla </th>
<th style="text-align:left; font-size: 10px; color:#8f8f8f; padding-bottom: 15px; width: 20%;">
Količina </th>
<th style="text-align:right; font-size: 10px; color:#8f8f8f; padding-bottom: 15px; width: 20%;">
EM (kos/m/colli,...) </th>
</tr>
</thead>
<tbody>
<tr id="mainsection">
<td> <p href="#" id="count" style="font-size: 13px; text-decoration: none; line-height: 1; color:#909090; margin-top:0px; margin-bottom:0;">
1</p> </td>
<td contenteditable style="padding-top:0px; padding-bottom:5px;">
<h4 style="font-size: 16px; line-height: 1; margin-bottom:0; color:#303030; font-weight:500; margin-top: 10px;">
<select class="form-control select2-multiple" id="dd_artikli" data-width="100%">
<option value="">Select country</option>
<?php
if (count($itemRecords_artikli) > 0) {
foreach ($itemRecords_artikli as $ct) {
?>
<option value="<?php echo $ct['id']; ?>">
<?php echo $ct['name']; ?>
</option>
<?php
}
}
?>
</select>
</h4>
</td>
<td contenteditable> <p href="#" style="font-size: 13px; text-decoration: none; line-height: 1; color:#909090; margin-top:0px; margin-bottom:0;"> </p> </td>
<td contenteditable style="padding-top:0px; padding-bottom:0; text-align: right;"> <p style="font-size: 13px; line-height: 1; color:#303030; margin-bottom:0; margin-top:0; vertical-align:top; white-space:nowrap;"> </p> </td>
</tr>
</tbody>
</table>
<script>
var number = 1;
document.getElementById("newsectionbtn").onclick = function() {
var container = document.getElementById("add_new");
var section = document.getElementById("mainsection");
var count = document.getElementById('count');
number++;
count.textContent = number.toString();
container.appendChild(section.cloneNode(true));
}
</script>
<
?php
/*
#Author: Sanjay Kumar
#Project: PHP MySQLi How To Use Select2 for Multiple Select Tutorial
#Email: onlinewebtutorhub#gmail.com
#Website: https://onlinewebtutorblog.com/
*/
// Include the database configuration file
require 'dbconfig.php';
$countrySelect = $conn->prepare("SELECT * FROM artikli");
$countrySelect->execute();
$countries = $countrySelect->get_result();
$itemRecords_artikli = array();
while ($item = $countries->fetch_assoc()) {
extract($item);
$itemDetails = array(
"id" => $id,
"name" => $naziv
);
array_push($itemRecords_artikli, $itemDetails);
}
?>
After drop-down bind run this command.
jQuery('#dd_artikli').select2();
Or use the jquery ready function.
$(document).ready(function() { jQuery('#dd_artikli').select2(); });
This is the main table which shows all the data from database, when I click the print it should only print the that row but it does not show up I get "Undefined variable: row" and im starting to think this has to do with this here the code for the table:
<div class="container" >
<div class="well" ">
<span class="pull-right"><a data-toggle="modal" data-target="#myModal" href="#myModal" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span> Enroll Pupil</a></span>
<div>
</div>
<table class="table table-striped table-bordered table-hover" >
<thead>
<th >Moble Number</th>
<th >First Name</th>
<th>Last Name</th>
<th>Section</th>
<th>Grade</th>
<th>Action</th>
</thead>
<tbody>
<?php
include('conn.php');
$query=mysqli_query($conn,"select * from `tbl_students`");
while($row=mysqli_fetch_array($query)){
?>
<tr s>
<td><?php echo $row['LRN']; ?></td>
<td><?php echo $row['FirstName']; ?></td>
<td><?php echo $row['LastName']; ?></td>
<td><?php echo $row['Section']; ?></td>
<td><?php echo $row['GradeLevel']; ?></td>
<td >
<span class="glyphicon glyphicon-edit"></span> Edit | |
<span class="glyphicon glyphicon-trash"></span> Delete | |
<span class="glyphicon glyphicon-edit"></span> Add Subject | |
<a class="btn btn-success" onclick="window.open('IndivPrintTableStudent.php').print();">Print</a>
<?php include('buttonstudent.php'); ?>
</td>
</tr>
<?php
}
?>
</tbody>
here is my database
<?php include"includes/config.php" ?>
<link rel="stylesheet" type="text/css" href="Print.css" media="print"></link>
<div class="container" >
<table>
<thead>
<th style="border: 3px solid #2F323A; text-align: center; padding-bottom: 8px;">Moble Number</th>
<th style="border: 3px solid #2F323A; text-align: center; width: 14%;">First Name</th>
<th style="border: 3px solid #2F323A; text-align: center; width: 14%;">Last Name</th>
<th style="border: 3px solid #2F323A; text-align: center; padding-bottom: 9px;">Section</th>
<th style="border: 3px solid #2F323A; text-align: center; width: 10%;">Grade</th>
</thead>
<tbody>
<?php
$query=mysqli_query($con,"SELECT * FROM tbl_students WHERE LRN='".$row['LRN']."'");
while($row=mysqli_fetch_array($query)){
?>
<tr style="background-color: #f0f8ff; border: 3px solid #2F323A;">
<td style="border: 3px solid #2F323A; padding-top: 15px; color: #2F323A;"><?php echo $row['LRN']; ?></td>
<td style="border: 3px solid #2F323A; padding-top: 15px; color: #2F323A;"><?php echo $row['FirstName']; ?></td>
<td style="border: 3px solid #2F323A; padding-top: 15px; color: #2F323A;"><?php echo $row['LastName']; ?></td>
<td style="border: 3px solid #2F323A; padding-top: 15px; color: #2F323A;"><?php echo $row['Section']; ?></td>
<td style="border: 3px solid #2F323A; padding-top: 15px; color: #2F323A;"><?php echo $row['GradeLevel']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
how do I get single data in individual manner? the error that I get s "Undefined variable: row" which you can see on the query. i dont know why it says that I only made this is table form just to see if i can get the actual data from a single student. I hope my question can be understandable.
Your button is linking to IndivPrintTableStudent.php but you aren't passing the ID of the clicked row in the URL, so that script doesn't know which row you wanted to display. $row['LRN'] in the second script isn't going to exist because it's part of a different script, variables are not carried across automatically from one script to another. You have to pass them in the URL.
You'd have something like
onclick="window.open('IndivPrintTableStudent.php?LRN=<?php echo $row["LRN"]; ?>').print();
in the print button on the first table.
And then the second script would use $_GET["LRN"] to retrieve that value from the URL and use it in the sql query.
(Beware of SQL injection though, learn how to use parameters and prepared statements to protect your database - see https://phpdelusions.net/mysqli for examples.)
So my problem can be seen in this picture:
How do I make every cell have the text at the same height? The last <th> (text+img) drags it down for some reason.
My css:
.table {
width: 100%;
padding: 0;
margin: 15px 0 0;
border-collapse: collapse
}
.table th {
text-align: left;
color: #fff;
background: 0 0;
text-transform: uppercase;
font-size: .9em;
line-height: 1em;
padding: .5em;
}
.table th.gold {
color: #ffdd45
}
.table td {
padding: .7em .5em .6em;
font-size: 1.1em;
line-height: 1.2em;
background: #222;
border: 2px solid rgba(0, 0, 0, 0);
vertical-align: middle;
}
<table class="table rate" style="margin-top: 0;">
<thead>
<tr>
<th>#</th>
<th>User</th>
<th>Number 1</th>
<th class="gold">Number 2</th>
<th>text+img</th>
</tr>
</thead>
<tbody id="players-table1">
<tr>
<td style="text-align: center;">1</td>
<td>
<a href="/user/9842394892389" class="username">
<img src="piclink" alt="Аvatar"><span>user0</span></a>
</td>
<td>4</td>
<td class="bold gold">500</td>
<td style="width:10%"><i>35x<img src="http://placekitten.com/301/301" style="width:55%;height:10%"/></i></td>
</tr>
<tr>
<td style="text-align: center;">2</td>
<td>
<a href="/user/9842394892389" class="username">
<img src="piclink" alt="Аvatar"><span>user</span></a>
</td>
<td>4</td>
<td class="bold gold">400</td>
<td style="width:10%"><i>35x<img src="piclink" style="width:55%;height:10%"/></i></td>
</tr>
<tr>
<td style="text-align: center;">3</td>
<td>
<a href="/user/9842394892389" class="username">
<img src="piclink" alt="Аvatar"><span>user2</span></a>
</td>
<td>3</td>
<td class="bold gold">300</td>
<td style="width:10%"><i>35x<img src="piclink" style="width:55%;height:10%"/></i></td>
</tr>
<tr>
<td style="text-align: center;">4</td>
<td>
<a href="/user/9842394892389" class="username">
<img src="piclink" alt="Аvatar"><span>user2</span></a>
</td>
<td>3</td>
<td class="bold gold">300</td>
<td style="width:10%"><i>35x<img src="piclink"/></i></td>
</tr>
</tbody>
</table>
There are 2 ways to fix this:
Decreasing the height of the image(which is what I did in answer), this was 10% before and I made it as 5%. The td content was pushing down due to that.
If you don't want to decrease the height of the image then you have to increase the height of the each row so that the height can easily fit-in.
so call is yours what to choose.
.table {
width: 100%;
padding: 0;
margin: 15px 0 0;
border-collapse: collapse
}
.table th {
text-align: left;
color: #fff;
background: 0 0;
text-transform: uppercase;
font-size: .9em;
line-height: 1em;
padding: .5em;
}
.table th.gold {
color: #ffdd45
}
.table td {
padding: .7em .5em .6em;
font-size: 1.1em;
line-height: 1.2em;
background: #222;
border: 2px solid rgba(0, 0, 0, 0);
vertical-align: middle;
border: 1px solid red;
}
<table class="table rate" style="margin-top: 0;">
<thead>
<tr>
<th>#</th>
<th>User</th>
<th>Number 1</th>
<th class="gold">Number 2</th>
<th>text+img</th>
</tr>
</thead>
<tbody id="players-table1">
<tr>
<td style="text-align: center;">1</td>
<td>
<a href="/user/9842394892389" class="username">
<img src="piclink" alt="Аvatar"><span>user0</span></a>
</td>
<td>4</td>
<td class="bold gold">500</td>
<td style="width:10%"><i>35x<img src="http://placekitten.com/301/301" style="width:55%;height:5%"/></i></td>
</tr>
<tr>
<td style="text-align: center;">2</td>
<td>
<a href="/user/9842394892389" class="username">
<img src="piclink" alt="Аvatar"><span>user</span></a>
</td>
<td>4</td>
<td class="bold gold">400</td>
<td style="width:10%"><i>35x<img src="http://placekitten.com/301/301" style="width:55%;height:5%"/></i></td>
</tr>
<tr>
<td style="text-align: center;">3</td>
<td>
<a href="/user/9842394892389" class="username">
<img src="piclink" alt="Аvatar"><span>user2</span></a>
</td>
<td>3</td>
<td class="bold gold">300</td>
<td style="width:10%"><i>35x<img src="http://placekitten.com/301/301" style="width:55%;height:5%"/></i></td>
</tr>
<tr>
<td style="text-align: center;">4</td>
<td>
<a href="/user/9842394892389" class="username">
<img src="piclink" alt="Аvatar"><span>user2</span></a>
</td>
<td>3</td>
<td class="bold gold">300</td>
<td style="width:10%"><i>35x<img src="http://placekitten.com/301/301" style="width:55%;height:5%"/></i></td>
</tr>
</tbody>
</table>
I am using simple_html_dom to gather data from another website and I am wondering how I can do a foreach for only the data as an a element.
$url = 'example.com';
html2 = file_get_html($url);
$download2 = $html2->find('table',1);
$data['ep_table'] = $download2->outertext;
The above code returns the following.
<table style="height: 341px;">
<tbody>
<tr style="height: 31px;">
<td style="height: 31px; width: 26px;">#</td>
<td style="height: 31px; width: 196px;">Song</td>
<td style="text-align: right; height: 31px; width: 82px;">Download</td>
</tr>
<tr style="height: 62px;">
<td style="height: 62px; width: 26px;">1</td>
<td style="height: 62px; width: 196px;">미쳐가지고 (I’m Crazy)</td>
<td style="text-align: right;height: 62px;width: 82px;">
<a href="http://example.com/South-Club-im-crazy/"
target="_blank"
rel="noopener">
<strong>
<button class="button_rbox" title="" type="button">
<span class="cnt">Download</span>
</button>
</strong>
</a>
</td>
</tr>
<tr style="height: 31px;">
<td style="height: 31px; width: 26px;">2</td>
<td style="height: 31px; width: 196px;">Someday</td>
<td style="text-align: right; height: 31px; width: 82px;">
<a href="http://example.com/South-Club-someday/"
target="_blank"
rel="noopener">
<strong>
<button class="button_rbox" title="" type="button">
<span class="cnt">Download</span>
</button>
</strong>
</a>
</td>
</tr>
<tr style="height: 93px;">
<td style="height: 93px; width: 26px;">3</td>
<td style="height: 93px; width: 196px;">안녕 (Hi/Bye)</td>
<td style="text-align: right; height: 93px; width: 82px;">
<a href="http://example.com/South-Club-hi/"
target="_blank"
rel="noopener">
<strong>
<button class="button_rbox" title="" type="button">
<span class="cnt">Download</span>
</button>
</strong>
</a>
</td>
</tr>
<tr style="height: 31px;">
<td style="width: 26px; height: 31px;">4</td>
<td style="width: 196px; height: 31px;">빗방울 (Raindrop)</td>
<td style="text-align: right; width: 82px; height: 31px;">
<a href="http://example.com/South-Club-raindrop/"
target="_blank" rel="noopener">
<strong>
<button class="button_rbox" title="" type="button">
<span class="cnt">Download</span></button>
</strong>
</a>
</td>
</tr>
</tbody>
</table>
How can I do a foreach, which searches only the html of $data['ep_table'] and not the entire page we're parsing for a a element?
I've tried this, with no luck.
foreach($data['ep_table']->find('a') as $track){
print $link = $track->href;
}
You're trying to use find() on plaintext, not a DOM object. You should do this:
$url = 'example.com';
html2 = file_get_html($url);
foreach( $html2->find('table', 1)->find('a') as $track)
{
echo $track->href;
}
It's also worth pointing out that find('table', 1) assumes the target table is the second <table> element in the retrieved markup.
I want to retrieve all media in left side and if media contain data will fill those data.
Here is my view:
<tbody>
<?php $i= 0; ?>
#foreach($print as $get)
#if(count($get->media_id)>0 && $get->Status === "Approved")
<tr>
<?php $i++; ?>
<td style="font-size: 16px; width: 25px; "><?php echo $i; ?></td>
<td style="font-size: 16px; width: 30px">{{$get->media_name}}</td>
<td style="font-size: 16px; width: 98px">{{$get->Date_Occured}}</td>
<td style="font-size: 16px; width: 80px">{{$get->Page_Number}}</td>
<td style="font-size: 16px; width: 150px">{{$get->Content_title}}</td>
<td style="font-size: 16px; width: 470px">{!! nl2br(e($get->Content_Description)) !!}</td>
</tr>
#endif
#endforeach
#foreach($media as $medias )
<?php $i++; ?>
<tr>
<td style="font-size: 16px; width: 25px; "><?php echo $i; ?></td>
<td style="font-size: 16px; width: 30px">{{$medias['media_name']}}</td>
<td style="font-size: 16px; width: 98px"></td>
<td style="font-size: 16px; width: 80px"></td>
<td style="font-size: 16px; width: 150px"></td>
<td style="font-size: 16px; width: 470px">Hakuna Taarifa kwa Leo</td>
</tr>
#endforeach
</tbody>
Here is my controller:
public function printpreview() {
$print = DB::table('media')
->leftjoin('content_forms', 'media.id', "=", 'content_forms.media_id')
->select('media.*','content_forms.*')
->whereDate('content_forms.created_at', DB::raw('CURDATE()'))
->get();
$media = media::all()->toArray();
return view('pdf.printview', compact('print', 'media'));
}