PDA

View Full Version : Show highest entry



Bar2aYunie
08-08-2010, 05:10 PM
Hello,

I have a db with names and corresponding values to the names. I also have a php code to display it all, pulling the info from the db. Now this isn't all very hard, but here's my question....

Per name, I've got up to three values and I would like to let php look for only the lowest value and display only that value. So if it were possible, I need to be able to insert the three values per field in the db and then have a code to get the lowest one, or I need to have three fields with the three values and let php get the lowest one out of those. The only problem there, is that the names per set of values must be the same, though I cannot add in the same name twice in the db.

Another thing... the values are now set to 'numeric float', as I need to multiply the lowest value with another set value. The only way (so far I've found then...) is to do that with float.

Can somebody help me out or at least point me in the right direction? I've searched for hours, but I just don't know where to look for.

Thank you in advance!

Edit: Sorry, mean show LOWEST

djr33
08-08-2010, 05:21 PM
That gets complex in a few ways, such as if you want to order the results by lowest value when searching.

I recommend using 3 fields and getting all of those for PHP.

Then create an array and use array_min() to pick out the lowest value. Easy.

Bar2aYunie
08-08-2010, 06:13 PM
Okay, so this is my code (a part of it though):



<?php
$column=1;
$formaatcat=mysql_real_escape_string($_GET['sizecat']);
$formaat=$_GET['size'];
$bedrukking=$_GET['color'];
$papiersoort=$_GET['material'];
$thumb_formaat=$_GET['thumb_size'];

echo "<table style='width:100%;'>\n\t\t<tr><td align='center' colspan='4'><h1>View the amounts and prices</h1></td></tr><tr>";
$finalQuery=mysql_query("SELECT DISTINCT * FROM `Flyers` WHERE `sizecat`='{$sizecat}' AND `color`='{$color}' AND `material`='{$material}' AND `thumb_size`='$thumb_size;");

while($item=mysql_fetch_array($finalQuery)){

$base_m=5;

{$item['price1'] = round ((($item['price1']+5) *1.85),0); $item['price01'] = $base_m*(ceil(($item['price1'])/$base_m));}

if ($column==1) {echo "<tr>";}
?>
<td width="50%" align="center"><?php echo "<img src='{$item['thumb_size']}' alt='{$item['thumb_size']}' border='2' style='border-color: #6E1244;' />" ?></td>
<td width="50%" align="left">Flyers <br />Size: <?php echo "{$item['sizecat']} &nbsp; {$item['size']}<br />{$item['color']}<br />{$item['material']}<br />{$item['Info']}" ?></td>
</tr><tr>
<td width="50%" align="center"><h1>Amounts</h1></td>
<td width="50%" align="center"><h1>Prices</h1></td>
</tr><tr>
<td width="50%" valign="top" align="center"><h4><?php
if ($item['amount1'] > "0") { echo $item['amont1'] ?> <br /> <?php }

?></h4></td>
<td width="50%" align="center"><h4><?php
if (($item['price1'] > "11") && ($item['price01'] < "100")) { ?> &euro;&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $item['price01']; ?>,- <?php }
elseif (($item['price1'] > "11") && ($item['price01'] < "1000")) { ?> &euro;&nbsp;&nbsp; <?php echo $item['price01']; ?>,- <?php }
elseif (($item['price1'] > "11") && ($item['price01'] >= "1000")) { ?> &euro; <?php echo $item['price01']; ?>,- <?php }?> <br />

<?php
?></h4></td>
<?php
$column++; if ($column==1) { echo "</tr>"; $column=2; }
}
echo "</tr><tr><td align='center' colspan='4'><input type=button value='Back' onClick='history.go(-1)'></td></tr></table>\r\n";


So, as you can see, there's the calculation for the value of price1. I've got three prices, but I left the price2 and price3 out of the code, same for amount2 and amount3.

I also have for every price three values. So I could make a array:



<?php
$priceList1 = array('price11', 'prijs12', 'prijs13');
$priceList2 = array('price21', 'prijs22', 'prijs23');
$priceList3 = array('price31', 'prijs32', 'prijs33');
?>


And then I need to find the lowest one of those? Do you know how? Well, I could search for that part... the ony trouble is... how do I use that in my current code? Since... I still need to do a little math with the one lowest outcome per price.

Or... I can let it display the way it is now.. for all three main prices, and the three values per price and then only show the lowest value of the outcome of that part? Which means after the calculation.

Are you following? Do you have any suggestions?
Thx for helping out!

Bar2aYunie
08-13-2010, 07:15 PM
Can anybody help me out here plz?