• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 470
  • Last Modified:

MySQL/PHP/Dreamweaver Question?

Not sure if this will be a function of PHP, MySQL or Dreamweaver but basically I need to know if I can do conditional formating on my PHP page based on the dynamic data that is diplayed.

I have a basic PHP page that returns dynamic data based on a parameter that is passed from a seperate form. I have built just a basic dynamic table in dreamweaver with a repeating section to display all the returned data. The data is returned like so:

Account Number     Address            Date                  Recall Rate        Exit Rate
12345678            100 Main St        10/2/2004            10.20%             11.57%
23456789            101 Elm St          9/1/2003               8.50%               7.56%
And so on

This data is displayed in a dynamic table with visible borders for each cell etc.

I need to use some type of conditional formating to color code the background and or font color of the Recall Rate and Exit Rate cells based on the value that is returned.

For example I would like to have the background color of the cell be red if the rate is above 12.00%, Yellow if the rate is between 10.00% - 12.00%, Green if the rate is below 10.00%. Ideally I would like to color code the font and the background ( Light green background , Dark green font, Light Yellow background, Dark yellow font etc.) but at this point I would be happy with just one of the other!

Thanks Rob!
1 Solution
I don't what you mean "dynamic" table. i guess you're using PHP and mySQL to retrieve data for your table.
take a look at this code..

$sql_data = mysql_query("SELECT recall_rate, exit_rate, * FROM table");

echo '<table>';
echo '<tr>';

echo '<td>Account Number</td>'
echo '<td>Address</td>'
echo '<td>Date</td>'
echo '<td>Recall Rate</td>'
echo '<td>Exit Rate</td>'

echo '</tr>';

while($row_data = mysql_fetch_array($sql_data)){

$rate = (float) $row_data['exit_rate'];

        if($rate < 10.0) {
                $color = 'Yellow';
        } elseif($rate < 12.0) {
                 $color = 'Green';
        } else {
                 $color = 'Red';

echo '<tr>';

echo '<td>' . $row_data['Account_Number'] . '</td>'
echo '<td>' . $row_data['Address'] . '</td>'
echo '<td>' . $row_data['Date'] . '</td>'
echo '<td>' . $row_data['Recall_Rate'] . '</td>'
echo '<td bgcolor="' . $color . '">' . $row_data['Exit_Rate'] . '</td>'

echo '</tr>';
echo '</table>';

That would be "draft" for your code. Any questions?


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now