473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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;

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. function check_system($sys)
  3. {
  4.         $srvCount;
  5.         $con = mysql_connect("localhost","username","passwd");
  6.         if (!$con)
  7.         {
  8.                 die('Could not connect: ' . mysql_error());
  9.         }
  10.  
  11.         mysql_select_db("Systems", $con);
  12.         foreach( $sys as $sysName => $sysID)
  13.         {
  14.                 $result = mysql_query("SELECT COUNT(system_id) FROM cc_servers WHERE system_id = $sysID");
  15.                 while($row = mysql_fetch_array($result))
  16.                 {
  17.                         $srvCount[$sysName] = $row['COUNT(system_id)'];
  18.                 }
  19.         }
  20. }
  21.  
  22. $auth = "dfnadbf08GA5G";
  23. $loc = $_GET["loc"];
  24. $USsystem = array("terra"=>2, "tellus"=>3);
  25. $EUsystem = array("gaia"=>1);
  26. if ( $auth == $_GET["auth"] )
  27. {
  28.         if($loc == USA)
  29.         {
  30.                 $system = $USsystem;
  31.                 check_system($system);
  32.         }
  33.         else if($loc == "EU")
  34.         {
  35.                 $system = $EUsystem;
  36.                 check_system($system);
  37.         }
  38. }
  39. else
  40. {
  41.         die('Wrong Authorization code');
  42. }
  43. ?>
  44.  
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."=".$sysID."=".$sysC)

Hope you understand what I mean.
Oct 28 '10 #1
1 2313
dlite922
1,584 Expert 1GB
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
Oct 28 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Zenobia | last post by:
I have a problem. I need to look up several values stored in arrays. Each value is stored as a pair. The first (number) represents the probability of this item occurring. For instance, in the...
6
by: mark4asp | last post by:
Suppose I have the following code. It functions to randomly select a city based upon the probabilities given by the key differences in the associative array. . Eg. because the key difference...
26
by: JGH | last post by:
How can I check if a key is defined in an associative array? var users = new array(); users = "Joe Blow"; users = "John Doe"; users = "Jane Doe"; function isUser (userID) { if (?????)
4
by: Robert | last post by:
I am curious why some people feel that Javascript doesn't have associative arrays. I got these definitions of associative arrays via goggle: Arrays in which the indices may be numbers or...
11
by: JehanNYNJ | last post by:
Is it possible to have an Object as the key for an Associative array like in the following example.... function Obj(var1, var2) { this.var1 = var1; this.var1 = var1;
14
by: Yereth Jansen | last post by:
Hi all, I encountered a problem with looping through an associative array. All worked perfectly with the following code: for (var menuItem in this.menuItems) { doSomething(); } where...
47
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
5
by: soup_or_power | last post by:
Hi I have an associative array like this: arr=30; arr=20;arr=40;arr=10; I want the sort function to sort keys in ascending order of the values on the right hand side with the following result:...
35
by: VK | last post by:
Whatever you wanted to know about it but always were affraid to ask. <http://www.geocities.com/schools_ring/ArrayAndHash.html>
11
by: lozwaldo | last post by:
Hi I could really do with some help here :) I am tring to display all of the results from the array without having to write everything out by hand like this echo get_currency(1, GBP);...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.