MySQL/PHP/Dreamweaver Question?

Posted on 2004-11-23
Last Modified: 2010-05-18
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!
Question by:ashvillerob
    1 Comment
    LVL 9

    Accepted 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

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API ( …
    I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now