Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Conditional formatting for PHP repeat region

New Here ,
Jun 15, 2010 Jun 15, 2010

Hi

I have a repeat region displaying a recordset. I would like to apply some form of conditional formatting if a result meets a certiain condition. In my code below, I would like the 'onsched' field to display according to a specific class if the result is less than 0:

<?php do { ?>
        <td><?php echo $row_RSonsched['name']; ?></td>
        <td><?php echo $row_RSonsched['predcurrent']; ?></td>
        <td><?php echo $row_RSonsched['Emerging_Level']; ?></td>
        <td><?php echo $row_RSonsched['onsched']; ?></td>
        </tr>
        <?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?>

Being new to PHP, is there any way I can have the class '.clsgood' apply if the value of ['onsched'] is less than 0?

Many thanks for your help in advance

TOPICS
Server side applications
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 16, 2010 Jun 16, 2010

Try this:

<?php do { ?>
        <td><?php echo  $row_RSonsched['name']; ?></td>
        <td><?php  echo $row_RSonsched['predcurrent']; ?></td>
         <td><?php echo $row_RSonsched['Emerging_Level'];  ?></td>
        <td<?php if( $row_RSonsched['onsched'] < 0) { ?> class="clsgood"<?php } ?>><?php echo  $row_RSonsched['onsched']; ?></td>
        </tr>
<?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));  ?>

Ed

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 17, 2010 Jun 17, 2010
LATEST

Thanks very much for your help. I managed to get everything to happen using the following code:

<td class="hr1"><?php echo $row_RSonsched['name']; ?></td>
            <td class="hr2"><?php echo $row_RSonsched['predcurrent']; ?></td>
            <td class="hr1"><?php echo $row_RSonsched'Emerging Level']; ?></td>
            <td> <?php if ($row_RSonsched['onsched'] > "0") echo '<span class="good">'.$row_RSonsched['onsched'].'</td>'; if ($row_RSonsched['onsched'] < "-0.79") echo '<span class="bad">'.$row_RSonsched['onsched'].'</td>';else echo '<span class="ok">'.$row_RSonsched['onsched'].'</td>';?> </td>

Where 'good', 'bad' and 'ok' are css classes that display red, green and amber

Many thanks again

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines