我想根据高度和重量检测桌子上的任何变化。该表将很长,因为每天将添加更多数据。但目前只有3行。
这是现在的样子(我只包括了重量的变化,因为我不知道如何包括高度):
# RESULTS
Loggades Längd Vikt BMI
2018-07-19, 15:40 1m 86cm 85 kg 25 (normal)
2018-07-18, 15:40 1m 85cm 84 kg 25 (normal) down
2018-07-17, 01:26 1m 86cm 86 kg 25 (normal) down
# TABLE
echo '<table>';
echo '<thead>';
echo '<tr>';
echo '<td class="width-datetime">Loggades</td>';
echo '<td class="width-height">Längd</td>';
echo '<td class="width-weight">Vikt</td>';
echo '<td class="width-bmi">BMI</td>';
echo '<td class="width-change"></td>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
# LOOP
foreach($get_data AS $data) {
# VARIABLE
$change_ = $data['data_weight'];
echo '<tr>';
# HEIGHT
echo '<td>';
echo datetime($data['datetime_occured'], true);
echo '</td>';
# HEIGHT
echo '<td>';
echo substr_replace($data['data_height'], 'm ', 1, 0).'cm';
echo '</td>';
# WEIGHT
echo '<td>';
echo $data['data_weight'].' kg';
echo '</td>';
# BMI
echo '<td>';
echo calculate_bmi($data['data_height'], $data['data_weight']);
echo '</td>';
# BMI
echo '<td class="width-change">';
# echo '<i class="fas fa-chevron-'.$change.'"></i>';
echo $change;
echo '</td>';
echo '</tr>';
# VARIABLE
$change = ($change_ < $data['data_weight'] ? 'up' : 'down');
}
echo '</tbody>';
echo '</table>';
这就是我想要的样子:
Loggades Längd Vikt BMI
2018-07-19, 15:40 1m 86cm 85 kg 25 (normal)
2018-07-18, 15:40 1m 85cm 84 kg 25 (normal) down
2018-07-17, 01:26 1m 86cm 86 kg 25 (normal) up
答案 0 :(得分:0)
您的循环应如下所示:
$x = 0;
foreach($get_data AS $data) {
if($x != 0) {
$change = ($change_ < $data['data_weight'] ? 'up' : 'down');
} else {
$change = '';
}
echo '<tr>';
# HEIGHT
echo '<td>';
echo datetime($data['datetime_occured'], true);
echo '</td>';
# HEIGHT
echo '<td>';
echo substr_replace($data['data_height'], 'm ', 1, 0).'cm';
echo '</td>';
# WEIGHT
echo '<td>';
echo $data['data_weight'].' kg';
echo '</td>';
# BMI
echo '<td>';
echo calculate_bmi($data['data_height'], $data['data_weight']);
echo '</td>';
# BMI
echo '<td class="width-change">';
# echo '<i class="fas fa-chevron-'.$change.'"></i>';
echo $change;
echo '</td>';
echo '</tr>';
$x++;
$change_ = $data['data_weight'];
}