I'm having trouble getting some PHP code to work.
Here is the function:
function getCellColor($dow) {
if (isset($_POST[$dow.alternative])) {
return "style=\"background: yellow; color:#fff;\"";
}
/*elseif (isset($_POST[$dow.shifthours]) && ($_POST[$dow.shifthours] == "OFF")) {
return "style=\"background: red; color:#fff;\"";
}*/
if ($_POST[$dow.shifthours] == "OFF") {
return "style=\"background: red; color:#fff;\"";
}
else {
return "style=\"background: green; color:#fff;\"";
}
}
Here is the section that outputs to the browser:
if (isset($_POST['submit'])) {
echo preTableFrmt();
foreach($engineer as $a => $b) {
echo "| [[$engineer[$a]]] || ".getCellColor('mon')." | $monday[$a] || ".getCellColor('tues')." | $tuesday[$a] || ".getCellColor('wed')." | $wednesday[$a] || ".getCellColor('thur')." | $thursday[$a] || ".getCellColor('fri')." | $friday[$a] || ".getCellColor('sat')." | $saturday[$a] || ".getCellColor('sun')." | $sunday[$a] <br />";
}
echo postTableFrmt();
}
else { echo "Waiting for data..."; }
The "Alternative" part is working. If it is checked, it overrides everything and does the "yellow" background.
The part that doesn't is when I leave the "Alternative" unchecked (default) and the drop down then is set to OFF (a form option from the drop down), it returns the "green" background. If I set it to another option (not OFF), it still goes to "green" background. The background needs to be red if set to OFF and anything else it should be "green".
Form Example HTML:
<select name="tuesshifthours[]" id="tuesshifthours">
<optgroup label="Select Shift Time">
<option value="OFF">OFF</option>
<option value="8am5pm">8AM-5PM</option>
<option value="7am7pm">7AM-7PM</option>
<option value="7pm7am">7PM-7AM</option>
</optgroup>
</select>
<label for="tuesalternative">A?</label>
<input type="checkbox" name="tuesalternative[]" id="tuesalternative" value="on" />
Additionally, here is my $_POST data (returns green background):
["monshifthours"]=>
array(1) {
[0]=>
string(3) "OFF"
}
$_POST data (also returns green background):
["monshifthours"]=>
array(1) {
[0]=>
string(3) "7am7pm"
}
$_POST[$dow.alternative]
is invalid PHP syntax, or at least it probably doesn't do what you think it does. What should this do? – deceze Feb 20 '11 at 8:06'mon'
in$dow
into'monalternative'
. It should be$dow . 'alternative'
to avoid a PHP notice. Same for$dow . 'shifthours'
. – David Harkness Feb 20 '11 at 8:12$dow
comes from the calling of the function, so that you can call it bygetCellColor("mon")
orgetCellColor("tues")
, that way I can reuse the code. The HTML dropdown names are namedmonshifthours
(all the way to sunday) andmonalternative
(all the way to sunday). I've updated my question with a sample of the dropdown/checkbox that is on my application. – drewrockshard Feb 20 '11 at 8:13