#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0

    Php bold the largest number out of 3 columns


    i have a mysql table like so
    Code:
    +------------------+-------------+------+-----+---------+----------------+
    | Field            | Type        | Null | Key | Default | Extra          |
    +------------------+-------------+------+-----+---------+----------------+
    | dyno_id          | int(11)     | NO   | PRI | NULL    | auto_increment |
    | orders_id        | int(11)     | YES  |     | NULL    |                |
    | customers_id     | int(11)     | NO   |     | 0       |                |
    | dyno_time        | time        | YES  |     | NULL    |                |
    | last_modified    | datetime    | YES  |     | NULL    |                |
    | date_purchased   | datetime    | YES  |     | NULL    |                |
    | customers_name   | varchar(64) | NO   |     |         |                |
    | dyno_runone_tq   | int(6)      | NO   |     | 0       |                |
    | dyno_runone_hp   | int(6)      | NO   |     | 0       |                |
    | dyno_runtwo_tq   | int(6)      | NO   |     | 0       |                |
    | dyno_runtwo_hp   | int(6)      | NO   |     | 0       |                |
    | dyno_runthree_tq | int(6)      | NO   |     | 0       |                |
    | dyno_runthree_hp | int(6)      | NO   |     | 0       |                |
    | dyno_engine      | varchar(32) | NO   |     |         |                |
    | dyno_model       | varchar(32) | NO   |     |         |                |
    | dyno_nitrous     | varchar(32) | NO   |     |         |                |
    | division         | varchar(64) | NO   |     | NULL    |                |
    +------------------+-------------+------+-----+---------+----------------+

    right now with this query

    Code:
    select *  
      from dyno_runs 
     order
        by division desc,
           greatest(dyno_runone_hp,dyno_runtwo_hp,dyno_runthree_hp)
    and this php

    PHP Code:

    if($orders['division'] != $cat) {
    ?>

       <table border="0" width="100%" cellspacing="0" cellpadding="0">
              <tr>
        <td   class="dataTableContent" align="center"colspan="2"><div align="center">
          
         <? echo "<h3>".$orders['division']."</h3>\r"?>
        </tr>
              <tr>
                <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
                  <tr class="dataTableHeadingRow">
                    <td class="dataTableHeadingContent" width="200">Name</td>
                   
                    <td class="dataTableHeadingContent"  width="200"align="center">First Run</td>
                    <td class="dataTableHeadingContent"  width="200"align="center">Second Run</td>
                    <td class="dataTableHeadingContent"  width="200"align="center">Third Run</td>
                  </tr>
    <? ?>

    <table border="" width="100%" cellspacing="0" cellpadding="0"> 

      <tr>
        <td  class="dataTableContent" align="left" width="200"><?php echo $orders['customers_name']; ?></td>
        
        <td  class="dataTableContent" align="center" width="200"><?php if ($orders['dyno_runone_hp'] == '') {
        echo 
    'N/A';
        } else {
        
        echo 
    $orders['dyno_runone_hp'] . ' HP '$orders['dyno_runone_tq'] . ' TQ';  
        
        }
        
    ?></td>
        <td  class="dataTableContent" align="center" width="200"><?php if ($orders['dyno_runtwo_hp'] == '') {
        echo 
    'N/A';
        } else {
        
        echo 
    $orders['dyno_runtwo_hp'] . ' HP '$orders['dyno_runtwo_tq'] . ' TQ';  
        
        }
    ?></td>
        <td  class="dataTableContent" align="center" width="200"><?php  if ($orders['dyno_runthree_hp'] == '') {
        echo 
    'N/A';
        } else {
        
        echo 
    $orders['dyno_runthree_hp'] . ' HP '$orders['dyno_runthree_tq'] . ' TQ';  
        
        }
    ?></td>
      </tr>
    </table>




    <?    /*    
                $dyno_schedule = tep_check_dyno_schedule($orders['orders_id']);

    $dyno_time = tep_check_dyno_time($orders['orders_id']);
    $dyno_time = strtotime("$dyno_time");
    $dyno_time = date('g:i a', $dyno_time);

      if ($dyno_schedule == '0') { 
       ?> 
       <?php
    }
    else 
    {
    echo $dyno_time; 
    }
    */
        
    $cat $orders['division'];
    }   

    ?>

    the output above sorts everything into tables and sorts the tables into divisions, I have a query that then sorts the highest HP out of the three columns per table group. what i need to do is then bold the HIGHEST value in the first row so you can see what the highest value is. these are the three columns the tables are sorted by against each returned result. so what i am looking for is a php script or a JavaScript that can pick out the highest HP number from the first row in the table group.

    dyno_runone_hp
    dyno_runtwo_hp
    dyno_runthree_hp



    Any help is appreciated.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    170
    Rep Power
    55
    This appears to be set up to only use one result, so I'm basing this off of that assumption; however it also looks like there are if statements or loops that aren't posted here. That being said, you should just be able to add a simple if statement before you output the table to identify the highest value and then output "<b></b>" around the text if it is the highest. Something like this:
    PHP Code:
    $highest 1;
    if(
    $orders['dyno_runone_hp'] < $orders['dyno_runtwo_hp']){
         
    $highest 2;
    elseif(
    $orders['dyno_runtwo_hp'] < $orders['dyno_runthree_hp']){
         
    $highest 3;

    Then in your table, you can just output the bold marks like this:
    PHP Code:
    if($highest 1){ echo "<b>"; }
    etc..... 
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0
    Originally Posted by SecurityDavid
    This appears to be set up to only use one result, so I'm basing this off of that assumption; however it also looks like there are if statements or loops that aren't posted here. That being said, you should just be able to add a simple if statement before you output the table to identify the highest value and then output "<b></b>" around the text if it is the highest. Something like this:
    PHP Code:
    $highest 1;
    if(
    $orders['dyno_runone_hp'] < $orders['dyno_runtwo_hp']){
         
    $highest 2;
    elseif(
    $orders['dyno_runtwo_hp'] < $orders['dyno_runthree_hp']){
         
    $highest 3;

    Then in your table, you can just output the bold marks like this:
    PHP Code:
    if($highest 1){ echo "<b>"; }
    etc..... 
    the if statements that are there just show N/A if the field has no data in it instead of returning a blank or 0. ill give your code a shot because i need a fresh set of eyes after messing with it.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0
    unfortunately

    PHP Code:
     $highest 1
    if(
    $orders['dyno_runone_hp'] < $orders['dyno_runtwo_hp']){      $highest 2
    elseif(
    $orders['dyno_runtwo_hp'] < $orders['dyno_runthree_hp']){      $highest 3; } 
    does not work i have tried a bunch of different combinations. the problem is if
    PHP Code:
    if($orders['dyno_runone_hp'] < $orders['dyno_runtwo_hp']){ 
    comes to be true, it never checks if the elseif is met because it will only move to the else if when the first statement is false.

    what i need is if run 1 is higher then run 2 or 3 it is bold, if run 2 is higher then run 1 and 3 it is bold, if run 3 is higher then 1 or 2 i need 3 to be bold.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    170
    Rep Power
    55
    Sorry. It must be past my bedtime. I'm not thinking clearly. Try this type of method instead.
    PHP Code:
    $highest $orders['dyno_runone_hp']; 
    if(
    $highest $orders['dyno_runtwo_hp']){
        
    $highest $orders['dyno_runtwo_hp'];
    }
    if(
    $highest $orders['dyno_runthree_hp']){
        
    $highest $orders['dyno_runthree_hp'];

    Then use it like this:
    PHP Code:
    if($highest $orders['dyno_runone_hp']){ echo "<b>"; }
    etc..... 
    I'm not sure if this is an up side or a down side; but if two items were equal, this method would bold them both.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0
    Originally Posted by SecurityDavid
    Sorry. It must be past my bedtime. I'm not thinking clearly. Try this type of method instead.
    PHP Code:
    $highest $orders['dyno_runone_hp']; 
    if(
    $highest $orders['dyno_runtwo_hp']){
        
    $highest $orders['dyno_runtwo_hp'];
    }
    if(
    $highest $orders['dyno_runthree_hp']){
        
    $highest $orders['dyno_runthree_hp'];

    Then use it like this:
    PHP Code:
    if($highest $orders['dyno_runone_hp']){ echo "<b>"; }
    etc..... 
    I'm not sure if this is an up side or a down side; but if two items were equal, this method would bold them both.
    Yes that method works perfect. Thank you

IMN logo majestic logo threadwatch logo seochat tools logo