function - using an if statement(true/false), not working
Posted: Mon Mar 05, 2007 7:53 pm
OK; probably some simple solution to this, but I really can't quite get this right.
I'm attempting to create a function that I can call on, after some manipulation (done that bit).
The question is:
Why is the Original NOT the same as the function?
The boolean value $alternateRows does not change? - Therefore not changing the colour of the cells in that row.
Additional Question:
Is there a way to change boolean expressions to the opposite of its current value?
In a simplified form similar to +1 as ++.
The Original; which works:
So, why doesn't this work the same?
I'm attempting to create a function that I can call on, after some manipulation (done that bit).
The question is:
Why is the Original NOT the same as the function?
The boolean value $alternateRows does not change? - Therefore not changing the colour of the cells in that row.
Additional Question:
Is there a way to change boolean expressions to the opposite of its current value?
In a simplified form similar to +1 as ++.
The Original; which works:
Code: Select all
// While - Display all results
while($myrow = $result->fetchRow()) {
// Alternate Row colours
if($alternateRows==false) {
echo '<tr><td>';
$alternateRows=true;
}
elseif($alternateRows==true) {
echo '<tr class="altrowcolor"><td>'; // altrowcolor class selected here; under "true" for alternateRows.
$alternateRows=false;
}
echo $myrow[1] . '</td><td>'; //
echo $myrow[15] . '</td><td>';
echo $myrow[3] . '</td><td>';
echo $myrow[5] . '</td><td>';
echo $myrow[6] . '</td><td>';
echo $myrow[7] . '</td><td>';
echo $myrow[8] . '</td><td>';
echo $myrow[9] . '</td><td>';
echo $myrow[10] . '</td><td>';
echo $myrow[11] . '</td><td>';
echo $myrow[12] . '</td><td>';
echo $myrow[13] . '</td><td>';
echo $myrow[14] . '</td>';
} // end While statementCode: Select all
// Function displays the table data, needs to be called more than once.
function displayResults($alternateRows, $myrow) {
// Alternate Row colours
if($alternateRows==false) {
echo '<tr><td>';
$alternateRows=true;
}
elseif($alternateRows==true) {
echo '<tr class="altrowcolor"><td>'; // altrowcolor class selected here; under "true" for alternateRows.
$alternateRows=false;
}
echo $myrow[1] . '</td><td>';
echo $myrow[15] . '</td><td>';
echo $myrow[3] . '</td><td>';
echo $myrow[5] . '</td><td>';
echo $myrow[6] . '</td><td>';
echo $myrow[7] . '</td><td>';
echo $myrow[8] . '</td><td>';
echo $myrow[9] . '</td><td>';
echo $myrow[10] . '</td><td>';
echo $myrow[11] . '</td><td>';
echo $myrow[12] . '</td><td>';
echo $myrow[13] . '</td><td>';
echo $myrow[14] . '</td>';
}
// While - Display all results
while($myrow = $result->fetchRow()) {
displayResults($alternateRows, $myrow);
}