I want to make a table weekly schedule , and I need to attach the dates in html markup. So far I got this code :
<table class="schedule-table">
<tr class="days-tr">
<td>
<span><?php echo $date = date("dS",strtotime('monday this week')).' - '.date("dS",strtotime("sunday this week")); ?> </span>
<span> <?php echo $date = date("M-Y",strtotime('monday this week')); ?></span>
</td>
<td data-workout-day="<?php echo $date = date("d-M-Y",strtotime('monday this week')); ?>">Monday</td>
<td data-workout-day="<?php echo $date = date("d-M-Y",strtotime('tuesday this week')); ?>">Tuesday</td>
<td data-workout-day="<?php echo $date = date("d-M-Y",strtotime('wednesday this week')); ?>">Wednesday</td>
<td data-workout-day="<?php echo $date = date("d-M-Y",strtotime('thursday this week')); ?>">Thursday</td>
<td data-workout-day="<?php echo $date = date("d-M-Y",strtotime('friday this week')); ?>">Friday</td>
<td data-workout-day="<?php echo $date = date("d-M-Y",strtotime('saturday this week')); ?>">Saturday</td>
<td data-workout-day="<?php echo $date = date("d-M-Y",strtotime('sunday this week')); ?>">Sunday</td>
</tr>
</table>
And here is the output :
<table class="schedule-table">
<tbody>
<tr class="days-tr">
<td>
<span>16th - 15th </span>
<span> Mar-2015</span>
</td>
<td data-workout-day="16-Mar-2015">Monday</td>
<td data-workout-day="10-Mar-2015">Tuesday</td>
<td data-workout-day="11-Mar-2015">Wednesday</td>
<td data-workout-day="12-Mar-2015">Thursday</td>
<td data-workout-day="13-Mar-2015">Friday</td>
<td data-workout-day="14-Mar-2015">Saturday</td>
<td data-workout-day="15-Mar-2015">Sunday</td>
</tr>
</tbody>
</table>
As you can see it takes the Monday date from following week instead of 9-Mar-2015 ? How to fix that to display it properly? (for example if we have Friday 13-Mar i want the mon, tues, thur to have dates from previous week not the following.
If you are assuming that you week is starting from monday
then first of all check
$day = date('l')
if($day != 'Monday'){
echo $date = date("d-M-Y",strtotime( "previous monday" ));
}
strtotime is hugely powerful and can accept a lot of strings to get the desired date. In this case, you want this week to get this weeks dates.
By changing 'next monday' etc to 'this week monday' you get the dates for Monday of this current week:
<table class="schedule-table">
<tr class="days-tr">
<td>
<span><?php echo $date = date("dS",strtotime('this week')).' - '.date("dS",strtotime("this week sunday")); ?> </span>
<span> <?php echo $date = date("M-Y",strtotime('monday this week')); ?></span>
</td>
<td data-workout-day="<?php echo $date = date("d-M-Y",strtotime('this week monday')); ?>">Monday</td>
<td data-workout-day="<?php echo $date = date("d-M-Y",strtotime('this week tuesday')); ?>">Tuesday</td>
<td data-workout-day="<?php echo $date = date("d-M-Y",strtotime('this week wednesday')); ?>">Wednesday</td>
<td data-workout-day="<?php echo $date = date("d-M-Y",strtotime('this week thursday')); ?>">Thursday</td>
<td data-workout-day="<?php echo $date = date("d-M-Y",strtotime('this week friday')); ?>">Friday</td>
<td data-workout-day="<?php echo $date = date("d-M-Y",strtotime('this week saturday')); ?>">Saturday</td>
<td data-workout-day="<?php echo $date = date("d-M-Y",strtotime('this week sunday')); ?>">Sunday</td>
</tr>
</table>
Generates:
<table class="schedule-table">
<tbody>
<tr class="days-tr">
<td>
<span>09th - 15th </span>
<span> Mar-2015</span>
</td>
<td data-workout-day="09-Mar-2015">Monday</td>
<td data-workout-day="10-Mar-2015">Tuesday</td>
<td data-workout-day="11-Mar-2015">Wednesday</td>
<td data-workout-day="12-Mar-2015">Thursday</td>
<td data-workout-day="13-Mar-2015">Friday</td>
<td data-workout-day="14-Mar-2015">Saturday</td>
<td data-workout-day="15-Mar-2015">Sunday</td>
</tr>
</tbody>
</table>
Related
I am very new to mysql and php. I'm making a restaurant menu. the problem is that on days the dishes are not in a row, they slip. what am I doing wrong?
I want my table to be like this table:
My code:
<table>
<tr>
<th><?php $d1=strtotime("monday this week");
echo date("Y-m-d", $d1)?></th>
<th><?php $d2=strtotime("tuesday this week");
echo date("Y-m-d", $d2)?></th>
<th><?php $d3=strtotime("wednesday this week");
echo date("Y-m-d", $d3)?></th>
<th><?php $d4=strtotime("thursday this week");
echo date("Y-m-d", $d4)?></th>
<th><?php $d4=strtotime("friday this week");
echo date("Y-m-d", $d4)?></th>
</tr>
<?php
while($rows=$result->fetch_assoc())
{
?>
<tr>
<td class="px-2 bg-success"><?php if($rows['datum'] == date("Y-m-d", $d1)){
echo $rows['nev'];}?></td>
<td class="px-2 bg-success"><?php if($rows['datum'] == date("Y-m-d", $d2)){
echo $rows['nev'];}?></td>
<tr>
<?php
}
?>
</table>
Thanks very much!
This is the current table:
$payment_date is date from which I want to subtract 1 month.
how could I do ?
<table class="table table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>Payment Month</th>
<th>Payment Date</th>
<th>Gross Salary </th>
<th>Total Deduction</th>
<th>Net Salary</th>
<th>Advance Salary</th>
<th>Incentive</th>
<th>Fine Deduction</th>
<th>Payment Amount</th>
<th class="hidden-print">Details</th>
</tr>
</thead>
<tbody>
<?php
if (!empty($payment_history)): foreach ($payment_history as $v_payment_history) :
?>
<tr>
<td><?php echo date('F-Y', strtotime($v_payment_history->payment_for_month)); ?></td>
<td><?php echo date('d-M-y', strtotime($v_payment_history->payment_date)); ?></td>
<td><?php echo $gross = $v_payment_history->basic_salary + $v_payment_history->house_rent_allowance + $v_payment_history->medical_allowance + $v_payment_history->special_allowance + $v_payment_history->fuel_allowance + $v_payment_history->phone_bill_allowance + $v_payment_history->other_allowance; ?></td>
<td><?php echo $deduction = $v_payment_history->tax_deduction + $v_payment_history->provident_fund + $v_payment_history->other_deduction; ?></td>
<td><?php echo $net_salary = $gross - $deduction; ?></td>
<td><?php echo $v_payment_history->award_amount; ?></td>
<td><?php echo $v_payment_history->incentive; ?></td>
<td><?php echo $v_payment_history->fine_deduction; ?></td>
<td><?php echo $v_payment_history->payment_amount; ?></td>
<td class="hidden-print"><?php echo btn_view('admin/payroll/salary_payment_details/' . $v_payment_history->salary_payment_id) ?></td>
</tr>
<?php
endforeach;
?>
<?php else : ?>
<tr>
<td colspan="9">
<strong>There is no data for display</strong>
</td>
</tr>
<?php endif; ?>
</tbody>
</table>
$payment_date is date from which I want to subtract 1 month.
how could I do ? I want payment only of last month from the month I'm giving payment
Easy!
<?php
$date = new DateTime();
$date->modify('-1 month');
echo $date->format('Y-m-d H:i:s');
See it here https://3v4l.org/UWaGY
You can also feed in a date string as a constructor. new DateTime('2014-09-18');
#LEARNER try it like this, check the output and code online here https://eval.in/806939:
<?php
//suppose that date is 2017/05/29
$yourDate = strtotime('2017/05/29 -1 month'); // substract 1 month from that date and converting it into timestamp
$desiredDate = date("Y-m-d", $yourDate);
echo $desiredDate;
?>
i want make a table than can be input with existing data, and also the table already exist even before the data inputted,table created based on how many days in this month(i.e: right now is october so it have 31 tables since october have 31 days).
The question are i want to put date number in column date and days in column days, basically date =1 so days of week=saturday, date =2 so days of week=sunday(based on current calendar) and so on
i not quite sure about the logic, cause every time i tried, it only fill the first div or its fill the whole divcheck out my code below
CODE
<table class="table table-bordered">
<thead>
<tr>
<th rowspan="2">Action</th>
<th rowspan="2">Date</th>
<th rowspan="2">Day of Week</th>
<th rowspan="2">Location</th>
<th rowspan="2">Brief Description of Activity </th>
<th colspan="6"><center>Project Code & Hour Worked</center> </th>
</tr>
<tr>
<th>A</th>
<th>Hours Worked</th>
<th>B</th>
<th>Hours Worked</th>
<th>C</th>
<th>Hours Worked</th>
</tr>
</thead>
<tbody>
<?php
$start = new DateTime('first day of this month');
$end = new DateTime('first day of this month + 1 month');
$period = new DatePeriod($start, new DateInterval('P1D'), $end);
for($i= 1; $i < date('t') + 1; $i++){
for($j =1;$j<=1;$j++){
echo "<td><a href='#modal-dialog' class='btn btn-xs btn-success' data-toggle='modal'><span class='fa fa-pencil'></span>i=".$i."</td>".PHP_EOL;
}
for($j =2;$j<=2;$j++){
foreach($period as $day){
echo "<td>".$day->format('M-d')."</td>".PHP_EOL;
}
for($j =1;$j<11;$j++){
echo "<td></td>".PHP_EOL;;
}
echo "</tr>";
}
?>
</tbody>
You are doing it wrong. You loop through the days and build the columns. Your loop through the days should build the rows.
<tbody>
<?php
$day = date('Y-m-d',strtotime('first day of this month'));
for($i= 1; $i < date('t') + 1; $i++){
?>
<tr>
<td><a href='#modal-dialog' class='btn btn-xs btn-success' data-toggle='modal'><span class='fa fa-pencil'></span>i=<?php echo $i; ?></td>
<td><?php echo date('M-d',strtotime($day)); ?></td>
<td><?php echo date('l',strtotime($day)); ?></td>
<?php
for($j =1;$j<=8;$j++){
echo "<td></td>".PHP_EOL;
}
?>
</tr>
<?php
$day = date('Y-m-d', strtotime('+1 day', strtotime($date)));
} ?>
</tbody>
I want chane column name date in to Day i change it to like this but it is error how i chane it to day when displaying data.
<tr>
<td width="" class="rounded" scope="col"><?php echo $row['date as day']; ?></td>
</tr>
This is normal code
</tr>
<tr>
<td width="" class="rounded" scope="col"><?php echo $row['date']; ?></td>
</tr>
I think you mean echo the day of the week. You would use the date function.
If your date is a date/time, not a timestamp you would use strtotime() to make it a timestamp first.
<?php echo date("D", strtotime($row['date'])); ?>
Will output Wed if it's a Wednesday
<?php echo date("l", strtotime($row['date'])); ?>
Will output Wednesday if it's a Wednesday. That's a lower case L not a number 1.
Query:
SELECT date as day FROM table;
and then :
<tr>
<td width="" class="rounded" scope="col"><?php echo $row["day"]; ?></td>
</tr>
HTH.
Okay, I'm sure there's a way to do this but I'm suffering from sleep deprivation and could really use some help.
Here's what I need. I have a table with headers and rows of data listed underneath - it looks great but, I need to add a table row between the rows of data when the month changes to separate out the months.
Here's what I have:
Date Time Event
08-31-2013 6:00 pm EST Horseshoe Tourney
09-07-2013 8:00 pm EST Movie Night
09-28-2013 5:00 pm EST Dinner on the Quad
10-12-2013 4:30 pm EST Sing-a-long
10-31-2013 7:00 pm EST Halloween Party
11-14-2013 4:00 pm EST Hay Ride
Here's what I need:
Date Time Event
AUGUST (to span the whole table row)
08-31-2013 6:00 pm EST Horseshoe Tourney
SEPTEMBER (to span the whole table row)
09-07-2013 8:00 pm EST Movie Night
09-28-2013 5:00 pm EST Dinner on the Quad
OCTOBER (to span the whole table row)
10-12-2013 4:30 pm EST Sing-a-long
10-31-2013 7:00 pm EST Halloween Party
NOVEMBER (to span the whole table row)
11-14-2013 4:00 pm EST Hay Ride
Any help would be greatly appreciated. Below is code I'm using to create the table now.
<table style="width: 100%;">
<thead>
<tr style="background-color:#8a0028; color:white;">
<th style="background-color:#8a0028; color:white; text-align:left;">Date</th>
<th style="background-color:#8a0028; color:white; text-align:left;">Time</th>
<th style="background-color:#8a0028; color:white; text-align:left;">Event</th>
</tr>
</thead>
<tbody>
<?php
// Write rows
mysql_data_seek($result, 0);
while ($row = mysql_fetch_assoc($result)) {
?>
<tr>
<td><?php echo date("M d, Y", strtotime($row['date']));?></td>
<td><?php echo $row['time'];?></td>
<td><?php echo $row['event'];?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
mysql_free_result($result);
?>
Here's what ended up working for me! Sure do appreciate the help!
<?php
// Write rows
mysql_data_seek($result, 0);
$month='';
while ($row = mysql_fetch_assoc($result)) {
if(date("F", strtotime($row['date']))!==$month){
$month=date("F", strtotime($row['date'])); ?>
<tr><td colspan="3"><?= $month ?></td></tr>
<?php
}
?>
<tr>
<td><?php echo date("M d, Y", strtotime($row['date']));?></td>
<td><?php echo $row['time'];?></td>
<td><?php echo $row['event'];?></td>
</tr>
<?php
$month=date("F", strtotime($row['date']));
}
?>
</tbody>
</table>
<?php
mysql_free_result($result);
?>
Try this:
<table style="width: 100%;">
<thead>
<tr style="background-color:#8a0028; color:white;">
<th style="background-color:#8a0028; color:white; text-align:left;">Date</th>
<th style="background-color:#8a0028; color:white; text-align:left;">Time</th>
<th style="background-color:#8a0028; color:white; text-align:left;">Event</th>
</tr>
</thead>
<tbody>
<?php
// Write rows
mysql_data_seek($result, 0);
$month='';
while ($row = mysql_fetch_assoc($result)) {
if(date("F", strtotime($row['date']))!==$month){
$month=date("F", strtotime($row['date'])); ?>
<tr><td colspan="3"><?= $month ?></td></tr>
<?php
}
?>
<tr>
<td><?php echo date("M d, Y", strtotime($row['date']));?></td>
<td><?php echo $row['time'];?></td>
<td><?php echo $row['event'];?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
mysql_free_result($result);
?>
I'd suggest something like this:
Essentially, at the beginning of each loop, you're testing to see if the month is different from the previous one. If it is, you output a new row.
<?php
mysql_data_seek($result, 0);
$last_month = '';
while ($row = mysql_fetch_assoc($result)) {
?>
<?php if (date("M", strtotime($row['month'])) != $last_month): ?>
<tr>
<td colspan="4"><?php echo date("M", strtotime($row['month'])); ?></td>
</tr>
<?php endif; ?>
<tr>
<td><?php echo date("M d, Y", strtotime($row['date']));?></td>
<td><?php echo $row['time'];?></td>
<td><?php echo $row['event'];?></td>
</tr>
<?php
$last_month = date("M", strtotime($row['month']));
}
?>