Displaying "Highest Price" indicator

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi there,

I have a list of values that I am displaying in a table (Not using a loop)

I want to be able to put a graphic next to the item with the hightest price.

I have all of the prices in a table.

Any ideas?



Re: Displaying "Highest Price" indicator

Steven wrote:
Quoted text here. Click to load it

Well ... you now have to do a loop.

Quoted text here. Click to load it

Find the highest priced item *before* printing the items; when printing
only put the graphic if it is the right item.

Quoted text here. Click to load it

A database table?
How do you get and print data from the database without loops? ?!?!?!

Quoted text here. Click to load it

Adapt this simple script that uses no database:

php$ cat max.php
$data = array(4, 7, 18, 3, 18, 6);

echo "Version a:\n";

$max = max($data);
foreach ($data as $value) {
  echo '    a) ', $value;
  if ($value == $max) echo ' GRAPHIC';
  echo "\n";

echo "\nVersion b:\n";

$max_index = array_search($max, $data);
foreach ($data as $k=>$v) {
  echo '    b) ', $v;
  if ($k == $max_index) echo ' GRAPHIC';
  echo "\n";


php$ php max.php
Version a:
    a) 4
    a) 7
    a) 18 GRAPHIC
    a) 3
    a) 18 GRAPHIC
    a) 6

Version b:
    b) 4
    b) 7
    b) 18 GRAPHIC
    b) 3
    b) 18
    b) 6

USENET would be a better place if everybody read:

Re: Displaying "Highest Price" indicator


Quoted text here. Click to load it

sort a copy of the array from high to low, get the price in the first row,
check the next one to be sure there isnt more than one with the same price
(unless you are certain this cannot happen). That way you wont have to
search the whole array but will only last for one row, or however many
there are of the same high price. When you print out your list, use an if
statement to see if the current price equals the high price, if so then
print your graphic.

Site Timeline