Background
I am trying to show a list of scheduled events for a user, to do this I am showing a bootstrap table with two columns, one is a generated list of 15m time intervals and the other is the event itself.
Scheduled events have a green background.
Problem
Due to the way I have setup my table and foreach loop I can't add a class to the <td> tag to change the background color depending on if there is an event or not.
What I have tried so far
Here is my view to display the data, I have added a div with a class 'event' which has a green background to denote that the event is scheduled.
<table class="table table-striped table-hover table-bordered">
<thead>
<tr>
<th>Time</th>
<th>Event</th>
<th></th>
</tr>
</thead>
<tbody>
<!-- shows times as 1472792400 => 6:00, 6:15, 6:30 -->
<?php foreach ($intervals as $seconds => $interval) : ?>
<tr>
<td class="col-md-1">
<div class="text-center">
<i class="fa fa-clock-o"></i>
<?php echo $interval; ?>
</div>
</td>
<td class="col-md-10">
<?php foreach ($events as $key => $event) : ?>
<?php if ($event->seconds_start == $seconds) : ?>
<div class="event-header">
<span class="label label-default"><?php echo $event->event; ?></span>
</div>
<?php elseif ($event->seconds_start < $seconds && $event->seconds_end >= $seconds + 900) : ?>
<div class="event"> </div>
<?php else : ?>
<!-- nothing -->
<?php endif; ?>
<?php endforeach; ?>
</td>
<td class="col-md-1"></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Here is my events table
and my css file
.event-header {
color:#fff;
font-weight:600;
background: #75a575;
border-bottom:1px solid #75a575 !important;
margin: -8px -10px -10px;
}
.event {
background: #abdbab;
margin: -8px -10px -10px;
}
here is how the events page looks so far
question
So basically if the event time equals the displayed time then I want to change the entire background color of the <td> to show that there is an event scheduled... but I can't add a class to the <td> because my logic block is within the <td></td> already. How do I do this?
UPDATE 1
Adding the <td> tags within the if statement (the ideal solution) like this...
<table class="table table-striped table-hover table-bordered">
<thead>
<tr>
<th class="text-center">Time</th>
<th>Event</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($intervals as $seconds => $interval) : ?>
<tr>
<td class="col-md-1">
<div class="text-center">
<i class="fa fa-clock-o"></i>
<?php echo $interval; ?>
</div>
</td>
<?php foreach ($events as $key => $event) : ?>
<?php if ($event->seconds_start == $seconds) : ?>
<td class="col-md-10 event-header">
<span class="label label-default"><?php echo $event->event; ?></span>
</td>
<?php elseif ($event->seconds_start < $seconds && $event->seconds_end >= $seconds + 900) : ?>
<td class="col-md-10 event"><td>
<?php else : ?>
<td class="col-md-10"><td>
<?php endif; ?>
<?php endforeach; ?>
<td class="col-md-1"></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Produces the following view:
UPDATE 2
Getting closer, by showing nothing in the else statement, however the layout is still very broken and I am having a hard time processing where I am going wrong...
<table class="table table-striped table-hover table-bordered">
<thead>
<tr>
<th class="text-center">Time</th>
<th>Event</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($intervals as $seconds => $interval) : ?>
<tr>
<td class="col-md-1">
<div class="text-center">
<i class="fa fa-clock-o"></i>
<?php echo $interval; ?>
</div>
</td>
<?php foreach ($events as $key => $event) : ?>
<?php if ($event->seconds_start == $seconds) : ?>
<td class="col-md-10 event-header">
<span class="label label-default"><?php echo $event->event; ?></span>
</td>
<?php elseif ($event->seconds_start < $seconds && $event->seconds_end >= $seconds + 900) : ?>
<td class="col-md-10 event">hello<td>
<?php else : ?>
<!-- nothing -->
<?php endif; ?>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
now shows...
as you can see, whene there is not event matching the time then no column is shown, however if I add the column in the else statement and even add a break the layout goes haywire...
The specification exists but it looks browsers doesn’t support it yet.
https://www.w3.org/TR/selectors4/#subject
The proposed code would be something like this:
!td .event-header { /* styles */ }
The only solution I see is to fall back to JavaScript. It could be worse than to refactor PHP thought.
If you want to change the style of a DOM node, you HAVE to apply CSS rules to it. You can't get around that. If you don't want <td class="..."> to do that, then you'll have to do <td style="..."> instead. One way or another, you'll HAVE to write CSS for this to happen.
Related
I am trying to align data list like this.
But I get output like this
I tried following code
$rawResult = unserialize($rawResult->sections);
$ans = array(0,1,2,3,4,5);
foreach ($rawResult as $questionKey => $questionArray) {
foreach ($questionArray['answers'] as $key => $value) {
if(in_array($value['given'][0], $ans)){
$answers[$key] = $value['given'][0];
}
}
foreach ($questionArray['questions'] as $id => $val) {
if (!preg_match("/How stressful has it been/i", $val['name'])) {
/*if($val['type'] == 'Single'){*/
$questions[$val['id']] = $val['name'];
}
}
}
ob_start();
global $csa_answers;
asort($answers);
$i=0;
$m=0;
$l=0;
$y=0;
global $pdf;
?>
<table class="progress-bar-container assessment-result" style="text-align:center;">
<tr>
<td><h3 style="font-weight: 700;font-size: 25px;line-height: 32px;color: #000;margin-bottom: 6px;font-family: 'Karla';">CSA Questions/Ratings</h3></td>
</tr>
<tr>
<td><span style="text-align: center;">Every CSA question and your response is listed below. Each question started out with the phrase,<br>
"How much have you been stressed by.....?"</span></td>
</tr>
</table>
<table class="table table-striped table-bordered" style="text-align:left;" width="620">
<tr>
<td><table width="310"><tr>
<td width="225" style="background-color: #EAE9E8;font-size:12px;">QUESTION</td>
<td width="80" style="background-color: #EAE9E8;font-size:12px;">RATING</td>
</tr>
<tr>
<?php foreach ($answers as $id => $ans) {
if(isset($questions[$id])){
$i++; ?>
<td style="<?php echo $c;?>"><span style="font-size:10px;"><?php echo str_replace('How much have you been stressed by ','',stripslashes($questions[$id]));?></span></td>
<td style="<?php echo $c;?>"><span style="font-size:10px;"><i><?php echo $csa_answers[$ans];?></i></span></td>
<?php
if ($l==0) {
$c= "background-color: #EAE9E8;";
$l++;
}
else{
$c="";
$l=0;
}
$i = 0;
$m++;
echo "</tr><tr >";
$y++;
if ($y==34) {
$l==0;
echo '<td></td><td></td></tr></table></td><td ><table width="310"><tr>
<td width="225" style="background-color: #EAE9E8;font-size:12px;">Question</td>
<td width="80" style="background-color: #EAE9E8;font-size:12px;">Rating</td>
</tr><tr>';
}
}
}
?>
<td></td><td></td></tr></table></td></tr><tr>
<?php echo '<td colspan="2" style="text-align:center;"><span class="score-desc" style="font-size:9px;">The choices for answering each question were:</span><br>
<span class="csmith-right-margin" style="font-size:9px;"> Not at all (Stress Free) </span>
<span class="csmith-right-margin" style="font-size:9px;"> A little bit </span>
<span class="csmith-right-margin" style="font-size:9px;"> Moderately </span>
<span class="csmith-right-margin" style="font-size:9px;"> Quite a bit </span>
<span class="csmith-right-margin" style="font-size:9px;"> Extremely </span>
<span class="csmith-right-margin" style="font-size:9px;"> Does not apply </span></td></tr>';
?>
</table>
<?php
$content = ob_get_clean();
return $content;
I tried many times to change the code but still get the wrong output. How can I fix this issue?
Table is not good for this, you can use:
1. <div style='display:inline-block'>Column 1</div> <div style='display:inline-block'>Column 2</div>
2. Use css flex box (prefer for responsive page reason).
3. Or if you familiar with table use <div style='display:table'></div> as css table not HTML table
I am not sure what is going wrong. But the system is printing the same values again and again, where it should echo the value only once where it is matching student_id in the delivery table. The full code I have edited as requested. This is not executing the query but able display the Table headings.
The code is :
<?php $min = $this->db->get_where('academic_settings' , array('type' =>'minium_mark'))->row()->description;?>
<?php $running_year = $this->db->get_where('settings' , array('type' => 'running_year'))->row()->description; ?>
<div class="content-w">
<div class="conty">
<?php include 'fancy.php';?>
<div class="header-spacer"></div>
<div class="content-i">
<div class="content-box">
<div class="row">
<div class="table-responsive">
<table width="100%" class="table table-striped table-lightfont">
<tbody>
<tr>
<td style="color:black !important; text-transform:uppercase; text-align:center;">
<?php echo get_phrase('Subject_Name');?> :
<span><?php echo $row['name'];?></span>
</td>
</tr>
<tr>
<td>
<table class="table table-padded">
<thead style="background-color:#90be2e; color:white;">
<tr style="padding-bottom:4px; padding-top:4px;">
<th style="color:white;"><?php echo get_phrase('Publish Date');?></th>
<th style="color:white;"><?php echo get_phrase('Assignment');?></th>
<th style="color:white;"><?php echo get_phrase('Faculty');?></th>
<th style="color:white;"><?php echo get_phrase('Last Date');?></th>
<th style="color:white;"><?php echo get_phrase('Submitted On');?></th>
<th style="color:white;"><?php echo get_phrase('Marks');?></th>
<th style="color:white;"><?php echo get_phrase('Feedback');?></th>
</tr>
</thead>
<tbody>
<?php
$uploader_id_student = $this->db->get_where('student', array('student_id' => $this->session->userdata('login_user_id')))->row()->student_id;
$invoices = $this->db->get_where('deliveries', array('student_id' => $uploader_id_student))->result_array();
foreach($invoices as $row2):
?>
<tr>
<td>
<?php echo $this->db->get_where('homework' , array('homework_code'=>$row2['homework_code']))->row()->upload_date;?>
</td>
<td>
<?php
$get_homework_data = $this->db->get_where('homework' , array('homework_code'=>$row2['homework_code']))->row();
echo wordwrap($get_homework_data->title,15,"<br>\n");
?>
</td>
<td>
<?php
echo $this->db->get_where('teacher' , array('teacher_id'=>$get_homework_data->uploader_id))->row()->first_name;
?>
<?php
echo $this->db->get_where('teacher' , array('teacher_id'=>$get_homework_data->uploader_id))->row()->last_name;
?>
</td>
<td>
<?php
$sampleDate1 = $this->db->get_where('homework' , array('homework_code'=>$row2['homework_code']))->row()->date_end;
$convertDate1 = date("d-m-Y", strtotime($sampleDate1));
echo $convertDate1;
?>
</td>
<td>
<?php
$sampleDate = $row2['date'];
$convertDate = date("d-m-Y", strtotime($sampleDate));
echo $convertDate;
?>
</td>
<td style="text-align:center;">
<?php echo $row2['mark'];?>
</td>
<td>
<?php echo wordwrap($row2['teacher_comment'],25,"<br>\n");?>
</td>
</tr>
<?php endforeach;?>
<!--<?php endforeach;?> -->
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
attached is screenshot of table Deliveries is there Deliveries Picture Download
Here is your code updated to fix the performance issues mentioned by Arnold Daniels.
<?php
$uploader_id_student = $this->session->userdata('login_user_id');
$invoices = $this->db->get_where('deliveries', array('student_id' => $uploader_id_student))->result_array();
foreach($invoices as $row2) {
$get_homework_data = $this->db->get_where('homework' , array('homework_code'=>$row2['homework_code']))->row();
$teacher = $this->db->get_where('teacher' , array('teacher_id'=>$get_homework_data->uploader_id))->row();
?>
<tr>
<td>
<?= $get_homework_data->upload_date ?>
</td>
<td>
<?= wordwrap($get_homework_data->title,25,"<br>\n") ?>
</td>
<td>
<?= $teacher->first_name . ' ' . $teacher->last_name ?>
</td>
</tr>
<?php
}
?>
It appears to be working fine as far as I could test it. Is there anything missing from the snippet you posted that could help reproduce your issue?
Edit:
So the complete code would be:
<?php
$min = $this->db->get_where('academic_settings' , array('type' =>'minium_mark'))->row()->description;
$running_year = $this->db->get_where('settings', array('type' => 'running_year'))->row()->description;
?>
<div class="content-w">
<div class="conty">
<?php include 'fancy.php'; ?>
<div class="header-spacer"></div>
<div class="content-i">
<div class="content-box">
<div class="row">
<div class="table-responsive">
<table width="100%" class="table table-striped table-lightfont">
<tbody>
<tr>
<td style="color:black !important; text-transform:uppercase; text-align:center;">
<?php echo get_phrase('Subject_Name'); ?> :
<span><?php echo $row['name']; ?></span>
</td>
</tr>
<tr>
<td>
<table class="table table-padded">
<thead style="background-color:#90be2e; color:white;">
<tr style="padding-bottom:4px; padding-top:4px;">
<th style="color:white;"><?php echo get_phrase('Publish Date'); ?></th>
<th style="color:white;"><?php echo get_phrase('Assignment'); ?></th>
<th style="color:white;"><?php echo get_phrase('Faculty'); ?></th>
<th style="color:white;"><?php echo get_phrase('Last Date'); ?></th>
<th style="color:white;"><?php echo get_phrase('Submitted On'); ?></th>
<th style="color:white;"><?php echo get_phrase('Marks'); ?></th>
<th style="color:white;"><?php echo get_phrase('Feedback'); ?></th>
</tr>
</thead>
<tbody>
<?php
$uploader_id_student = $this->db->get_where('student', array('student_id' => $this->session->userdata('login_user_id')))->row()->student_id;
$invoices = $this->db->get_where('deliveries', array('student_id' => $uploader_id_student))->result_array();
foreach ($invoices as $row2) :
$homework_data = $this->db->get_where('homework', array('homework_code' => $row2['homework_code']))->row();
$teacher = $this->db->get_where('teacher', array('teacher_id' => $get_homework_data->uploader_id))->row();
?>
<tr>
<td>
<?php echo $homework_data->title->upload_date; ?>
</td>
<td>
<?php
echo wordwrap($homework_data->title, 15, "<br>\n");
?>
</td>
<td>
<?php
echo $teacher->first_name;
?>
<?php
echo $teacher->last_name;
?>
</td>
<td>
<?php
$sampleDate1 = $homework_data->date_end;
$convertDate1 = date("d-m-Y", strtotime($sampleDate1));
echo $convertDate1;
?>
</td>
<td>
<?php
$sampleDate = $row2['date'];
$convertDate = date("d-m-Y", strtotime($sampleDate));
echo $convertDate;
?>
</td>
<td style="text-align:center;">
<?php echo $row2['mark']; ?>
</td>
<td>
<?php echo wordwrap($row2['teacher_comment'], 25, "<br>\n"); ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
I would need to see the contents of the included file "fancy.php" to be sure. There was an extra endforeach statement, but I'm guessing that it came from somewhere beyond the scope of the snippet you updated. I would need to see the whole content of the file and the content of the included script in order to determine the true nature of the error.
<!--<?php endforeach;?> -->
Remove this Line
Here is the code for notification code:
<?php if(isset($notification) && $notification->result() >0 ){?>
<div class="panel-heading pull-right col-md-6"
style="height:140px; margin-top:-140px; background-color:white; overflow-y: scroll;">
<h5><strong>Student with 3 Consecutive Absences</strong></h5>
<table class="table">
<thead>
<th>Course Code-Section</th>
<th>Student Name</th>
<th>View</th>
</thead>
<tbody>
<?php foreach($notification->result() as $notif)
{
if($notif->Total >=3)
{
?>
<tr>
<td><?php echo $notif->Course_Code_Section?</td>
<td><?php echo $notif->Student?></td>
<td>
<form action="<?php echo base_url();?>index.php/attendance/check" method="post" target="_blank">
<input type="hidden" name="CID" value="<?php echo $notif->CID;?>">
<button class="btn btn-xs btn-success"><i class="icon-eye-open"></i> View</button>
<?php echo form_close();?>
</td>
</tr>
</div>
<?php }?>
<?php }?>
</tbody>
</table>
</div>
<?php }?>
Here is the notification view, the default background color is white. Therefore, I want it to make the background color red when the condition met.
Try this:
<?php
$style = '';
if(isset($notification) && $notification->result() > 0 )
{
$style = 'style="color:red"';
// Put your css style property here
}
?>
Html:
<div <?php echo $style ?>>
</div>
You can do as -
<?php
if(your condition)
{
?>
<style>
#your_div
{
background:red !important;
}
</style>
<?php
}
else
{
?>
<style>
#your_div
{
background:white !important;
}
</style>
<?php
}
?>
If your condition is true in PHP you can just this line in your tag:
<tr bgcolor="#FF0000">
I don't know if my html code will appear or not. Please refer this site:
https://www.w3schools.com/tags/att_tr_bgcolor.asp
Please try this code ,i hope this is your condition
<?php
$bcolor ='background-color:white';
if(isset($notification) && $notification->result() >0 ){
$bcolor ='background-color:white';
}?>
<div class="panel-heading pull-right col-md-6"
style="height:140px; margin-top:-140px; <?php echo $bcolor ;?> overflow-y: scroll;">
<h5><strong>Student with 3 Consecutive Absences</strong></h5>
<table class="table">
<thead>
<th>Course Code-Section</th>
<th>Student Name</th>
<th>View</th>
</thead>
<tbody>
<?php foreach($notification->result() as $notif)
{
if($notif->Total >=3)
{
?>
<tr>
<td><?php echo $notif->Course_Code_Section?</td>
<td><?php echo $notif->Student?></td>
<td>
<form action="<?php echo base_url();?>index.php/attendance/check" method="post" target="_blank">
<input type="hidden" name="CID" value="<?php echo $notif->CID;?>">
<button class="btn btn-xs btn-success"><i class="icon-eye-open"></i> View</button>
<?php echo form_close();?>
</td>
</tr>
</div>
<?php }?>
<?php }?>
</tbody>
</table>
</div>
try
<?php
$bg_red = '';
if (condition) {
$bg_red = '<style="background-color: red;">';
}
?>
<tr <php? echo $bg_red; ?>>
<td></td>
<td></td>
<td></td>
</tr>
I have a following code which I have written to convert the download monitor output to html table.
<div class="table-1">
<table width="100%">
<thead>
<tr>
<th>Lab Title</th>
<th>Download</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php $dlm_download->the_title(); ?></td>
<td><a href="<?php $dlm_download->get_the_download_link(); ?>">
<?php $dlm_download->the_title(); ?> (<?php echo $dlm_download->get_the_download_count(); ?>)</a></td>
</tr>
</tbody>
</table>
</div>
however this gives me the output as shown below
how can I modify code so the table headers aren't repeated for every download.
Update: here's the php code
<?php global $dlm_page_addon; ?>
<div class="download_category download_group">
<!-- <h3><?php //echo $category->name; ?> <?php //if ( $category->count ) : ?>(<?php //echo $category->count; ?>)<?php //endif; ?></h3> -->
<?php while ( $downloads->have_posts() ) : $downloads->the_post(); ?>
<?php $dlm_download = new DLM_Download( get_the_ID() ); ?>
<?php $template_handler = new DLM_Template_Handler(); $template_handler->get_template_part( 'content-download', $format, $dlm_page_addon->plugin_path() . 'templates/', array( 'dlm_download' => $dlm_download ) ); ?>
<?php endwhile; ?>
</div>
As far as I understand, this code passes the array $dlm_download to the template. The template code is the one with the table and has repeating table headers. I want to have a three column table with download title, category and download link.
Replace <th></th> tags with <td></td> and use <strong>Content</strong>
<div class="table-1">
<table width="100%">
<thead>
<tr>
<td><strong>Lab Title</strong></td>
<td>Download</td>
</tr>
</thead>
<tbody>
<tr>
<td><?php $dlm_download->the_title(); ?></td>
<td><a href="<?php $dlm_download->get_the_download_link(); ?>">
<?php $dlm_download->the_title(); ?> (<?php echo $dlm_download->get_the_download_count(); ?>)</a></td>
</tr>
</tbody>
</table>
</div>
Here's my div and my iframe:
<div class="divMinorView">
<!-- Selected order-->
<iframe id="ifMinor" src="#"></iframe>
</div>
Also inside the iframe I have this table, it populates rows of data, sometimes 10 rows, maybe 50 to 100 at times.:
<table id="slot_table">
<thead>
<tr>
<th> </th>
</tr>
</thead>
<tbody id="slot_rows">
<?php if (count($slots) == 0): ?>
<tr class="none">
<td colspan=9>No slots found in that minor code.</td>
</tr>
<?php else: ?>
<?php foreach ($slots as $slot): ?>
<tr <?php if ($slot->is_expired($end_db_fmt)) { echo 'class="expired"'; } ?>>
<td class="actions">
<?php if (!$slot->is_expired($end_db_fmt)): ?>
<span class="expire_slot">X</span>
<span class="expire_error faux_links tip" data-tip="There has been an error"><img src="/images/thumbs_down_ico.png" width="13" height="13"></span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
<tr>
<td> </td>
<td>
<select id="new_style" name="style">
<?php foreach ($style_list as $style): ?>
<option value="<?php echo $style->get_id(); ?>"><?php echo $style->get_desc(); ?></option>
<?php endforeach; ?>
</select>
</td>
<td class="ints"><input id="new_price" type="text" name="price_point" value=""></td>
<td><input type="submit" name="add_slot" id="add_slot" value="Add slot"></td>
</tr>
</table>
I've tried setting the css to height:100%; as well as setting body{ margin:0; }
I've tried setting the iframe id to scrolling="no".
I'm not sure why I can't get the data to populate to the bottom of the screen. It shouldn't need to scroll, unless maybe the data being populated fills up all the real estate on the page than scroll.
Any help would be greatly appreciated. Should i be using some jquery to fix the height issues?
$("iframe").height($("#divMinorView").height());
$(window).resize(function() {
$("iframe").height($("#divMinorView").height());
});