[英]php value from db table subtracted by multiple row values in different table
I am struggling to work out how to get the original entitlement
figure from table1 and then subtract the 'days' from each request from table2 in start date order. 我正在努力研究如何从表1中获得原始entitlement
数字,然后按开始日期顺序从表2中的每个请求中减去“天数”。
1st table gets their entitlement figure 第一张桌子获得他们的权利数字
2nd table gets the requests 第二张桌子得到请求
Any guidance would be appreciated, the output i am looking for is: 任何指导将不胜感激,我正在寻找的输出是:
Start Date End Date Days to be taken Days remaining
- - - 22
01 Sep 2011 03 Sep 2011 3 19
10 Sep 2011 11 Sep 2011 2 17
Here is my code: 这是我的代码:
$is_business_result = mysql_query('SELECT * FROM holiday_entitlement_business_manual WHERE employee = \'' . $username . '\' AND academic_year = \'' . $acyear . '\' ');
if($is_business = mysql_fetch_array($is_business_result)) {
echo '<div style="float:left; width:400px;">';
echo '<table width="100%">
<tr>
<td><strong>Name:</strong></td>
<td>'.$is_business['employee'].'</td>
</tr>
<tr>
<td><strong>Entitlement:</strong></td>
<td>'.$is_business['entitlement'].' '.$is_business['units'].'</td>
</tr>
<tr>
<td><strong>Department / Division:</strong></td>
<td>'.$is_business['division'].'</td>
</tr>
<tr>
<td><strong>Line Manager:</strong></td>
<td>'.$is_business['line_manager'].'</td>
</tr>
</table>';
echo '<br/>';
echo '<br/>';
echo '<br/>';
echo '</div>';
echo '<table width="100%">
<tr>
<td><strong>Start Date</strong></td>
<td><strong>End Date</strong></td>
<td><strong>Days to be taken</strong></td>
<td><strong>Days remaining</strong></td>
</tr>';
echo '<tr>';
echo '<td>-</td>';
echo '<td>-</td>';
echo '<td>-</td>';
echo '<td>'.$is_business['entitlement'].'</td>';
echo '</tr>';
}
$requests_result = mysql_query('SELECT * FROM requests WHERE employee = \'' . $username . '\' AND approved = 1 AND academic_year = \'' . $acyear . '\' ORDER BY start_date ASC');
while($requests = mysql_fetch_array($requests_result)) {
$start_date = new DateTime($requests['start_date']);
$end_date = new DateTime($requests['end_date']);
$timestamp_start_date = $start_date->getTimestamp();
$timestamp_end_date = $end_date->getTimestamp();
$formatted_start_date = date("d M Y", $timestamp_start_date);
$formatted_end_date = date("d M Y", $timestamp_end_date);
echo '<tr>';
echo '<td>'.$formatted_start_date.'</td>';
echo '<td>'.$formatted_end_date.'</td>';
echo '<td>'.$requests['days'].'</td>';
echo '</tr>';
}
echo'</table>';
TABLES 桌子
CREATE TABLE IF NOT EXISTS `requests` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`academic_year` varchar(255) NOT NULL,
`employee` varchar(255) NOT NULL,
`start_date` varchar(255) NOT NULL,
`end_date` varchar(255) NOT NULL,
`days` varchar(255) NOT NULL,
`user` int(20) NOT NULL,
`approved` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
CREATE TABLE IF NOT EXISTS `holiday_entitlement_business_manual` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`academic_year` varchar(255) NOT NULL,
`employee` varchar(255) NOT NULL,
`full_part_time` varchar(255) NOT NULL,
`weekly_hours` varchar(255) NOT NULL,
`division` varchar(255) NOT NULL,
`date_of_commencement` varchar(255) NOT NULL,
`entitlement` varchar(255) NOT NULL,
`units` varchar(255) NOT NULL,
`line_manager` varchar(255) NOT NULL,
`length_of_service` varchar(255) NOT NULL,
`band` varchar(255) NOT NULL,
`new_entitlement` varchar(255) NOT NULL,
`weekly_entitlement` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=227 ;
我想员工是一个外键,如果它是,那么您可以基于员工加入两个表,然后获取所有数据并从php的权利中减去天数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.