Displaying "Highest Price" indicator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven

    Displaying "Highest Price" indicator

    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?

    Cheers

    Steven


  • Pedro Graca

    #2
    Re: Displaying "Highes t Price" indicator

    Steven wrote:[color=blue]
    > I have a list of values that I am displaying in a table (Not using a loop)[/color]

    Well ... you now have to do a loop.
    [color=blue]
    > I want to be able to put a graphic next to the item with the hightest price.[/color]

    Find the highest priced item *before* printing the items; when printing
    only put the graphic if it is the right item.
    [color=blue]
    > I have all of the prices in a table.[/color]

    A database table?
    How do you get and print data from the database without loops? ?!?!?!
    [color=blue]
    > Any ideas?[/color]

    Adapt this simple script that uses no database:

    php$ cat max.php
    <?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($m ax, $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:



    Comment

    • Theo

      #3
      Re: Displaying &quot;Highes t Price&quot; indicator

      "Steven" <webmaster@deep web.co.nz> wrote in news:w34ed.1342 9$mZ2.792819
      @news02.tsnz.ne t:
      [color=blue]
      >
      > Any ideas?[/color]

      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.

      Comment

      Working...