Jump to content

find the min price from database array


AdRock

Recommended Posts

I have a list of products in database and some have the same itemid but a different price depending on size

 

What i want to do i if the itemid has more than one size, take the smallest price and then add the word "From" at the beginning.

 

I've tried using the MIN() function but can't get it to do what i want.

 

If there is only one size it works fine but if there is more than one it just says "From 0.00"

 

while ($row = $result->fetch()) {
if(!isset($items[$row['itemid']]))
{
	$items[$row['itemid']] = $row;
}
$items[$row['itemid']]['sizes'][$row['size']] = $row['price'];  ### CHANGED ###
}
foreach($items AS $subitem) {
list($prodid, $itemid, $item, $size, $description, $shortdesc, $image, $price) = $subitem;

//Create field for item name based upon record count	
if(count($subitem['sizes']) > 1)
{
	/*$item_name_field = "<ul>\n";
	foreach($subitem['sizes'] as $size => $price) ### CHANGED ###
	{*/

	//}
	//$item_name_field .= "<ul>\n";
	$myprice = explode(".",number_format(min($subitem['price']),2));
	$item_name_field .= "<li>From ".$myprice[0].".".$myprice[1]." {$size}</li>\n";
}
else
{
	$myprice = explode(".",number_format($subitem['price'],2));
	$item_name_field .= "<li><span class=\"ucprice\">&#163;".$myprice[0]."<?span><span class=\"lcprice\">.".$myprice[1]."</span></li>\n";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.