Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rather Interesting Question - if at all possible

Status
Not open for further replies.

james0816

Programmer
Jan 9, 2003
295
US
when displaying several records from a table....is it at all possible to say "bold" the highest value in a column?

i.e. i display 5 line items

1 test1 3 9
2 test2 6 14
3 test3 1 6
4 test4 12 9
5 test5 7 10

so the 12 and 14 would get displayed in BOLD font (or something else to designate that it is the highest in that column)
 
Yes, it's possible.

One way:[ol][li]Perform a query to get the maximum of the 3rd column. Remember that value.[/li][li]Perform a query to get the maximum of the 4th column. Remember that value[/li][li]Perform the query to fetch all values.[/li][li]Loop through the values printing them out, and when a column's value matches the max for that column, output bold tags around the value.[/li][/ol]


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
james-

Yes indeed it is. In order to accomplish this you would have to read the data from the table into an array and then search the array for the highest value for each column.

Then use xhtml's <strong> tag to make the correct items bold.

Remember: try not to think of if you can accomplish something but rather how.

Robert Carpenter
"You and I have need of the strongest spell that can be found to wake us from the evil enchantment of worldliness." - C.S. Lewis (The Weight of Glory)

 
Just try a subquery like

"Select max(COLUMN3) from TABLE"

and remember that value in a variable like $max_value
If you then put an if-statement to your output like

Code:
if $row[COLUMN3] = $max_value
{
   echo "<b>" . $row[COLUMN3] . "</b>";
}
else
{
   echo $row[COLUMN3];
}

that should do it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top