How do I create a menu table - php

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:

Related

CodeIgniter 3 pretty date and time format

I have made a Register and Login Application with CodeIgniter 3 and Bootstrap.
I am showing all the users in a view:
<table class="table table-striped table-bordered">
<thead>
<tr>
<th class="col-md-1">ID</th>
<th class="col-md-3">Full name</th>
<th class="col-md-6">Email</th>
<th class="col-md-4">Date created</th>
<th class="col-md-4">Date updated</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user): ?>
<tr>
<td><?php echo $user->id ?></td>
<td><?php echo $user->fname . " " . $user->lname; ?></td>
<td><?php echo $user->email; ?></td>
<td><?php echo $user->created_at ?></td>
<td><?php echo $user->updated_at ?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
I want the Date created and Date updated columns to be formatted nicely: March 10 2001, at 15:16:03.
I have loaded the date helper.
What shall I write in the view to get a "pretty" date and time format like that mentioned above?
You could try this way
Example only
<?php echo date('M d Y');?> at <?php echo date('H:i:s', strtotime('15:16:03'));?>
Prints
January 14 2018 at 15:16:03
A full, pretty date and time format Sunday, Nov 19, 2017 at 00:34:36 will be output by writing:
<?php echo nice_date($user->created_at, 'l, M d, Y') . ' at '. nice_date($user->created_at, 'H:i:s'); ?>
And Nov 19, 2017 at 00:34:36 will be output by writing:
<?php echo nice_date($user->created_at, 'M d, Y') . ' at '. nice_date($user->created_at, 'H:i:s'); ?>

how to subtract 1 month from any date and fetch value of that month from database

$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;
?>

PHP table based on month and date

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>

Displaying date from monday to sunday

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>

Need to change column name when data fetch in to table in php code

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.

Categories