Jump to content

Need help.. Trying to highlight/bold largest number in a column


kycivicboy

Recommended Posts

OK i have my database setup to show weights of the item.  How can i tell my php script to highlight the cell in the table or bold the weight in the table?  i hope what im trying to say makes sense.

 

instead of sorting it by the heaviest weight i just want to be able to highlight/or bold the heaviest weight so the names of the items stay in alphabetical order. and i will be able to tell which item is heavier.

 

Any help would really be appreciated. thanks

Link to comment
Share on other sites

  • 3 weeks later...

sorry ive been busy lately. here is the code.

 

I would like to highlight the heaviest weight in row 5.

 

<tr>
<td width="25%"><?php print( $row[1] ); ?> </font></td>
<td width="25%"><?php print( $row[2] ); ?> </font></td>
<td width="25%"><?php print( $row[3] ); ?> </font></td>
<td width="25%"><?php print( $row[4] ); ?> </font></td>
<td width="25%"><?php print( $row[5] ); ?> </font></td>
</tr>
<?php
    }
    mysql_free_result( $result );
?>
</table>

Link to comment
Share on other sites

try this

<table align=center width=800>
<?php
$sql = "SELECT * FROM tablename";
$res = mysql_query($sql) or die (mysql_error());
$weight = array();
while($w = mysql_fetch_array($res)){
$weight[] = $w[5];
}
$max = max($weight);
mysql_free_result($res);
$result = mysql_query($sql) or die (mysql_error());
while($row = mysql_fetch_array($result)){
  if($row[5] == $max){
  $maxweight = "<b>".$row[5]."</b>";
  } else {
  $maxweight = $row[5];
  }
?>
<tr>
<td width="20%"><?php print( $row[1] ); ?> </font></td>
<td width="20%"><?php print( $row[2] ); ?> </font></td>
<td width="20%"><?php print( $row[3] ); ?> </font></td>
<td width="20%"><?php print( $row[4] ); ?> </font></td>
<td width="20%"><?php print( $maxweight ); ?> </font></td>
</tr>
<?php
}
?>
</table>

 

Should be able to plug in your table info, I just pasted my working script

 

Ray

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.