Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not to be pedantic, but there are probably easier and less headache-inducing ways to write this! But in short, I'd say that your code is almost there. Is your table showing up in one colour that depends on the time of day? I'd say it has something to do with your session variables only being <strong><em>set</em></strong>, and never <strong><em>unset</em></strong>...</p> <p>Would something like this suffice:</p> <pre><code>... while($Row = mysql_fetch_assoc($Result)) { $timezone = new DateTimeZone( "Europe/London" ); $date = new DateTime(); $date-&gt;setTimezone( $timezone ); $now = $date-&gt;format( 'H:i' ); foreach($Row as $field =&gt; $value) { if ($field == 'b1') { if ($value &gt; $now) { $Table.= "&lt;td style='font-size:14px; background-color:YELLOW;' align='center'&gt;$value&lt;/td&gt;"; } else { $Table.= "&lt;td style='font-size:14px; background-color:WHITE;' align='center'&gt;$value&lt;/td&gt;"; } } else if ($field == 'b2') { if ($value &gt; $now) { $Table.= "&lt;td style='font-size:14px; background-color:RED;' align='center'&gt;$value&lt;/td&gt;"; } else { $Table.= "&lt;td style='font-size:14px; background-color:WHITE;' align='center'&gt;$value&lt;/td&gt;"; } } else { $Table.= "&lt;td style='font-size:14px; background-color:WHITE;' align='center'&gt;$value&lt;/td&gt;"; } } $Table.= "&lt;/tr&gt;"; } ... </code></pre> <p>Sorry if I got the colours mixed up! ;) Hope this helps point you on the right track!</p> <p><em><strong>EDIT:</em></strong></p> <p>Check the commented PHP code below for a solution to switching colours every 3 rows (hope I got it right - wrote it really fast!)</p> <pre><code>... // so this is my understanding of what I think this code must do // based on what your original code looks like and what your original // question was highlighting... // based on how you're calling the rows and checking the fields for // values 'b1' and 'b2', I'm making an assumption here that the fields // 'b1' and 'b2' will always both exist in every row you parse. Maybe you // shouldn't be checking the '$field' variable for equivalence to 'b1' // or 'b2', but rather the '$value' variable? Regardless, I'm throwing down // this code for the '$RowCt' question you had, it will alternate between the // 3 colours...I hope it helps... $RowCt = 0; while($Row = mysql_fetch_assoc($Result)) { // get the time, that's all working ok... $timezone = new DateTimeZone( "Europe/London" ); $date = new DateTime(); $date-&gt;setTimezone( $timezone ); $now = $date-&gt;format( 'H:i' ); // increase the counter, work out the colour... $RowCt++; $background_color = 'white'; if ($RowCt % 3 == 1) $background_color = 'red'; if ($RowCt % 3 == 2) $background_color = 'yellow'; $Table.="&lt;tr style='background-color:". $background_color .";'&gt;"; foreach($Row as $field =&gt; $value) $Table.= "&lt;td style='font-size:14px;' align='center'&gt;$value&lt;/td&gt;"; $Table.= "&lt;/tr&gt;"; } ... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload