Jump to content


Photo

products avaluable


  • Please log in to reply
1 reply to this topic

#1 blacknight

blacknight
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts
  • Locationsaint john

Posted 07 September 2006 - 06:45 PM

we have a database where we store computer parts and we use these parts to build systems this is what i need to know say i have somthen like this

video card x 10
mobo        x 5
Ram        x 7
Hdd          x 9

no by looking at this i can see that i can make 5 systems but i was a php script that compares up to 10 compoments and tells me how many i can make can some one help me with this?
if at first your fail google will give you a pass

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 07 September 2006 - 07:21 PM

Assuming 1 of each per system

<?php
$parts = array(
        'video card' => 10,
        'mobo'       => 5,
        'Ram'        => 7,
        'Hdd'        => 9 
);

echo min($parts);    // --> 5
?>

Or, direct from DB,
<?php
$sql = "SELECT MIN(qty) FROM parts";
$res = mysql_query($sql);
echo mysql_result ($res, 0, 0);
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users