JJohnsenDK Posted September 19, 2007 Share Posted September 19, 2007 Hey im trying to get the highest number from this while loop: <?php $stockQuery = dbquery("SELECT DISTINCT(color_no), products_id, units_out, units_in FROM ".DB_PREFIX."stock WHERE products_id = '".$product."' GROUP BY color_no"); $i=1; while($stockRow = dbarray($stockQuery)){ $stock = getMaxGarnStock($stockRow['products_id'], $stockRow['color_no']); if($stock < $items){ $_SESSION['item_error'] = "Vi beklager, men vi har desværre kun $stock stk. på lager af den ønskede vare ud af dine $items ønskede stk.. Dette gør, at vi først kan sende det resterende antal når vi får leveret fra vores leverandør. Vil du bestille varen(e) alligevel?"; $_SESSION['temp_items'] = $items; $_SESSION['temp_product'] = $product; } $i++; } ?> The getMaxGarnStock() function returns the amout of items which is left at the stock of the perticuilar product. So if we say the query/while loop gives me these four numbers: 4, 11, 7 and 19 How do i get the highest number of these four numbers? Quote Link to comment https://forums.phpfreaks.com/topic/69860-solved-getting-the-highest-number-from-a-while-loop/ Share on other sites More sharing options...
trq Posted September 19, 2007 Share Posted September 19, 2007 Better to do it within your query if possible but something like.... <?php $max = 0; while($stockRow = dbarray($stockQuery)){ $stock = getMaxGarnStock($stockRow['products_id'], $stockRow['color_no']); if($stock < $items){ $_SESSION['item_error'] = "Vi beklager, men vi har desværre kun $stock stk. på lager af den ønskede vare ud af dine $items ønskede stk.. Dette gør, at vi først kan sende det resterende antal når vi får leveret fra vores leverandør. Vil du bestille varen(e) alligevel?"; $_SESSION['temp_items'] = $items; $_SESSION['temp_product'] = $product; } $i++; } if ($stock > $max) { $max = $stock; } // $max now holds the highest number. ?> Quote Link to comment https://forums.phpfreaks.com/topic/69860-solved-getting-the-highest-number-from-a-while-loop/#findComment-350925 Share on other sites More sharing options...
JJohnsenDK Posted September 19, 2007 Author Share Posted September 19, 2007 Brilliant!... i have been working with this for hours and it really got me screwed! so THANK YOU so very much mate Quote Link to comment https://forums.phpfreaks.com/topic/69860-solved-getting-the-highest-number-from-a-while-loop/#findComment-350929 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.