Table not being styled correctly through if conditional statements
I have been stuck on this issue for a while. My conditional loop is suppose to style the win percent based on the score. i.e bad has red background colour, average = orange, good = blue, great = dark blue.
The problem is, it either goes straight to the first if statement(even if winpercentage
is NOT between 250 & 500) or straight to the else statement. It never passes and styles through any of the other if statements. Every winpercentage is styled identically.
Can someone notice any problem with the logic?
<?php foreach ($data_table['data']['my_data'] as $key => $value) { ?>
<tr>
foreach ($data_table_stats['data'] as $k => $v) {
$invalid_flag = FALSE;
if ($value['tank_id'] == $v['tank_id'] && $value['mark_of_mastery'] == 4) { ?>
<td class="stats-font" width="10%">
<?php echo $winPercentage . '%'; ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['all']['battles']); ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['all']['wins']); ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['all']['losses']); ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['all']['frags']); ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['max_frags']); ?>
</td>
<td class="stats-font" width="10%">
<?php if ($winPercentage > 250 && $winPercentage < 500 ) {
$invalid_flag = TRUE;
echo "<div class='bad'>$winPercentage</div>";
}
elseif ($winPercentage >= 500 && $winPercentage < 1500 ) {
$invalid_flag = TRUE;
echo "<div class='average'>$winPercentage</div>";
}
elseif ($winPercentage >= 1500 && $winPercentage < 2000 ) {
$invalid_flag = TRUE;
echo "<div class='good'>$winPercentage</div>";
}
elseif ($winPercentage > 2000) {
$invalid_flag = TRUE;
echo "<div class='great'>$winPercentage</div>";
}
else {
echo "<div class='no_rank'>$winPercentage</div>";
}
?>
</td>
</tr>
<?php }
} ?>
</tbody>
</table>
php html css
add a comment |
I have been stuck on this issue for a while. My conditional loop is suppose to style the win percent based on the score. i.e bad has red background colour, average = orange, good = blue, great = dark blue.
The problem is, it either goes straight to the first if statement(even if winpercentage
is NOT between 250 & 500) or straight to the else statement. It never passes and styles through any of the other if statements. Every winpercentage is styled identically.
Can someone notice any problem with the logic?
<?php foreach ($data_table['data']['my_data'] as $key => $value) { ?>
<tr>
foreach ($data_table_stats['data'] as $k => $v) {
$invalid_flag = FALSE;
if ($value['tank_id'] == $v['tank_id'] && $value['mark_of_mastery'] == 4) { ?>
<td class="stats-font" width="10%">
<?php echo $winPercentage . '%'; ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['all']['battles']); ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['all']['wins']); ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['all']['losses']); ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['all']['frags']); ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['max_frags']); ?>
</td>
<td class="stats-font" width="10%">
<?php if ($winPercentage > 250 && $winPercentage < 500 ) {
$invalid_flag = TRUE;
echo "<div class='bad'>$winPercentage</div>";
}
elseif ($winPercentage >= 500 && $winPercentage < 1500 ) {
$invalid_flag = TRUE;
echo "<div class='average'>$winPercentage</div>";
}
elseif ($winPercentage >= 1500 && $winPercentage < 2000 ) {
$invalid_flag = TRUE;
echo "<div class='good'>$winPercentage</div>";
}
elseif ($winPercentage > 2000) {
$invalid_flag = TRUE;
echo "<div class='great'>$winPercentage</div>";
}
else {
echo "<div class='no_rank'>$winPercentage</div>";
}
?>
</td>
</tr>
<?php }
} ?>
</tbody>
</table>
php html css
Does $winPercentage output what you expect? Your if statements seem to work fine for me when I test them.
– Second2None
Dec 30 '18 at 5:25
You do have a small error: <tr> foreach ($data_table_stats['data'] as $k => $v) { should be <tr> <?php foreach ($data_table_stats['data'] as $k => $v) { you also need another closing curly bracket before tbody
– Second2None
Dec 30 '18 at 5:28
@Second2None Ah yep. Sorry was a mistake when copying. Yes, it does print the correct output. It's just the styling isnt correct for corresponding values.
– copernicus1996
Dec 30 '18 at 5:40
What does your CSS look like?
– BobRodes
Dec 30 '18 at 6:30
add a comment |
I have been stuck on this issue for a while. My conditional loop is suppose to style the win percent based on the score. i.e bad has red background colour, average = orange, good = blue, great = dark blue.
The problem is, it either goes straight to the first if statement(even if winpercentage
is NOT between 250 & 500) or straight to the else statement. It never passes and styles through any of the other if statements. Every winpercentage is styled identically.
Can someone notice any problem with the logic?
<?php foreach ($data_table['data']['my_data'] as $key => $value) { ?>
<tr>
foreach ($data_table_stats['data'] as $k => $v) {
$invalid_flag = FALSE;
if ($value['tank_id'] == $v['tank_id'] && $value['mark_of_mastery'] == 4) { ?>
<td class="stats-font" width="10%">
<?php echo $winPercentage . '%'; ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['all']['battles']); ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['all']['wins']); ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['all']['losses']); ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['all']['frags']); ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['max_frags']); ?>
</td>
<td class="stats-font" width="10%">
<?php if ($winPercentage > 250 && $winPercentage < 500 ) {
$invalid_flag = TRUE;
echo "<div class='bad'>$winPercentage</div>";
}
elseif ($winPercentage >= 500 && $winPercentage < 1500 ) {
$invalid_flag = TRUE;
echo "<div class='average'>$winPercentage</div>";
}
elseif ($winPercentage >= 1500 && $winPercentage < 2000 ) {
$invalid_flag = TRUE;
echo "<div class='good'>$winPercentage</div>";
}
elseif ($winPercentage > 2000) {
$invalid_flag = TRUE;
echo "<div class='great'>$winPercentage</div>";
}
else {
echo "<div class='no_rank'>$winPercentage</div>";
}
?>
</td>
</tr>
<?php }
} ?>
</tbody>
</table>
php html css
I have been stuck on this issue for a while. My conditional loop is suppose to style the win percent based on the score. i.e bad has red background colour, average = orange, good = blue, great = dark blue.
The problem is, it either goes straight to the first if statement(even if winpercentage
is NOT between 250 & 500) or straight to the else statement. It never passes and styles through any of the other if statements. Every winpercentage is styled identically.
Can someone notice any problem with the logic?
<?php foreach ($data_table['data']['my_data'] as $key => $value) { ?>
<tr>
foreach ($data_table_stats['data'] as $k => $v) {
$invalid_flag = FALSE;
if ($value['tank_id'] == $v['tank_id'] && $value['mark_of_mastery'] == 4) { ?>
<td class="stats-font" width="10%">
<?php echo $winPercentage . '%'; ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['all']['battles']); ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['all']['wins']); ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['all']['losses']); ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['all']['frags']); ?>
</td>
<td class="stats-font" width="5%">
<?php echo number_format($value['max_frags']); ?>
</td>
<td class="stats-font" width="10%">
<?php if ($winPercentage > 250 && $winPercentage < 500 ) {
$invalid_flag = TRUE;
echo "<div class='bad'>$winPercentage</div>";
}
elseif ($winPercentage >= 500 && $winPercentage < 1500 ) {
$invalid_flag = TRUE;
echo "<div class='average'>$winPercentage</div>";
}
elseif ($winPercentage >= 1500 && $winPercentage < 2000 ) {
$invalid_flag = TRUE;
echo "<div class='good'>$winPercentage</div>";
}
elseif ($winPercentage > 2000) {
$invalid_flag = TRUE;
echo "<div class='great'>$winPercentage</div>";
}
else {
echo "<div class='no_rank'>$winPercentage</div>";
}
?>
</td>
</tr>
<?php }
} ?>
</tbody>
</table>
php html css
php html css
asked Dec 30 '18 at 5:16
copernicus1996copernicus1996
11
11
Does $winPercentage output what you expect? Your if statements seem to work fine for me when I test them.
– Second2None
Dec 30 '18 at 5:25
You do have a small error: <tr> foreach ($data_table_stats['data'] as $k => $v) { should be <tr> <?php foreach ($data_table_stats['data'] as $k => $v) { you also need another closing curly bracket before tbody
– Second2None
Dec 30 '18 at 5:28
@Second2None Ah yep. Sorry was a mistake when copying. Yes, it does print the correct output. It's just the styling isnt correct for corresponding values.
– copernicus1996
Dec 30 '18 at 5:40
What does your CSS look like?
– BobRodes
Dec 30 '18 at 6:30
add a comment |
Does $winPercentage output what you expect? Your if statements seem to work fine for me when I test them.
– Second2None
Dec 30 '18 at 5:25
You do have a small error: <tr> foreach ($data_table_stats['data'] as $k => $v) { should be <tr> <?php foreach ($data_table_stats['data'] as $k => $v) { you also need another closing curly bracket before tbody
– Second2None
Dec 30 '18 at 5:28
@Second2None Ah yep. Sorry was a mistake when copying. Yes, it does print the correct output. It's just the styling isnt correct for corresponding values.
– copernicus1996
Dec 30 '18 at 5:40
What does your CSS look like?
– BobRodes
Dec 30 '18 at 6:30
Does $winPercentage output what you expect? Your if statements seem to work fine for me when I test them.
– Second2None
Dec 30 '18 at 5:25
Does $winPercentage output what you expect? Your if statements seem to work fine for me when I test them.
– Second2None
Dec 30 '18 at 5:25
You do have a small error: <tr> foreach ($data_table_stats['data'] as $k => $v) { should be <tr> <?php foreach ($data_table_stats['data'] as $k => $v) { you also need another closing curly bracket before tbody
– Second2None
Dec 30 '18 at 5:28
You do have a small error: <tr> foreach ($data_table_stats['data'] as $k => $v) { should be <tr> <?php foreach ($data_table_stats['data'] as $k => $v) { you also need another closing curly bracket before tbody
– Second2None
Dec 30 '18 at 5:28
@Second2None Ah yep. Sorry was a mistake when copying. Yes, it does print the correct output. It's just the styling isnt correct for corresponding values.
– copernicus1996
Dec 30 '18 at 5:40
@Second2None Ah yep. Sorry was a mistake when copying. Yes, it does print the correct output. It's just the styling isnt correct for corresponding values.
– copernicus1996
Dec 30 '18 at 5:40
What does your CSS look like?
– BobRodes
Dec 30 '18 at 6:30
What does your CSS look like?
– BobRodes
Dec 30 '18 at 6:30
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53975435%2ftable-not-being-styled-correctly-through-if-conditional-statements%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53975435%2ftable-not-being-styled-correctly-through-if-conditional-statements%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Does $winPercentage output what you expect? Your if statements seem to work fine for me when I test them.
– Second2None
Dec 30 '18 at 5:25
You do have a small error: <tr> foreach ($data_table_stats['data'] as $k => $v) { should be <tr> <?php foreach ($data_table_stats['data'] as $k => $v) { you also need another closing curly bracket before tbody
– Second2None
Dec 30 '18 at 5:28
@Second2None Ah yep. Sorry was a mistake when copying. Yes, it does print the correct output. It's just the styling isnt correct for corresponding values.
– copernicus1996
Dec 30 '18 at 5:40
What does your CSS look like?
– BobRodes
Dec 30 '18 at 6:30