By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,442 Members | 1,457 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,442 IT Pros & Developers. It's quick & easy.

Displaying "Highest Price" indicator

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Steven wrote:
I have a list of values that I am displaying in a table (Not using a loop)
Well ... you now have to do a loop.
I want to be able to put a graphic next to the item with the hightest price.
Find the highest priced item *before* printing the items; when printing
only put the graphic if it is the right item.
I have all of the prices in a table.
A database table?
How do you get and print data from the database without loops? ?!?!?!
Any ideas?


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($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:
http://www.expita.com/nomime.html
http://www.netmeister.org/news/learn2quote2.html
http://www.catb.org/~esr/faqs/smart-questions.html
Jul 17 '05 #2

P: n/a
"Steven" <we*******@deepweb.co.nz> wrote in news:w34ed.13429$mZ2.792819
@news02.tsnz.net:

Any ideas?


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.
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.