How to compare values in associative array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rickard Hill
    New Member
    • Sep 2010
    • 3

    How to compare values in associative array

    I haven't been working very much with arrays before, do I'm pretty clueless of how to do this. Hope someone have the time to help out.

    I have the following code;

    Code:
    <?php
    function check_system($sys)
    {
            $srvCount;
            $con = mysql_connect("localhost","username","passwd");
            if (!$con)
            {
                    die('Could not connect: ' . mysql_error());
            }
    
            mysql_select_db("Systems", $con);
            foreach( $sys as $sysName => $sysID)
            {
                    $result = mysql_query("SELECT COUNT(system_id) FROM cc_servers WHERE system_id = $sysID");
                    while($row = mysql_fetch_array($result))
                    {
                            $srvCount[$sysName] = $row['COUNT(system_id)'];
                    }
            }
    }
    
    $auth = "dfnadbf08GA5G";
    $loc = $_GET["loc"];
    $USsystem = array("terra"=>2, "tellus"=>3);
    $EUsystem = array("gaia"=>1);
    if ( $auth == $_GET["auth"] )
    {
            if($loc == USA)
            {
                    $system = $USsystem;
                    check_system($system);
            }
            else if($loc == "EU")
            {
                    $system = $EUsystem;
                    check_system($system);
            }
    }
    else
    {
            die('Wrong Authorization code');
    }
    ?>
    What I need to do, is for the php script to loop through the srvCount and compare which system has the lowest amount of active servers ($sysC), and then echo something like terra=2=27 ($sysN."=".$sys ID."=".$sysC)

    Hope you understand what I mean.
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Reduce your problem to a simple example.

    Explain what you're trying to do with two arrays.

    I can't find $sysC in your code, or the rest of your variables. I don't know what they mean. By the way you haven't received an answer yet, nobody else here understand your problem either.

    Try again and be accurate & concise about your problem.

    Dan

    Comment

    Working...