Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl, create array from all returned mysql rows

Status
Not open for further replies.

roywills

Technical User
Feb 18, 2008
6
US
i am havin a bit of trouble with a report I am trying to generate. I have 2 databases on 2 seperate mysql hosts. Database 1 holds monitoring info and Database 2 holds account info (again, these are 2 different mysqwl hosts).

What I am trying to accomplish is being able to sort by the account_id gathered from Database 2. However, I must first find all monitored hostnames to be able to pull the account_id based on host_name from db1. Here is what iu have so far"

Database 1:
SELECT services.host_id, hosts.host_name FROM services, hosts WHERE services.host_id = hosts.host_id;

This gives me the hostname monitored which i can then search for in db2 below.

Database 2:
select account_id from ve where ve_id=(select ve_id from om_website where name = '$hostname');

$hostname comes from DB1.

My problem is that I can do while loop for each hostname from db1 to find the account_id from db2, but i can sort this via the account_id since each hostname will only have account_id returned.

Does anyone see a way I can perhaps store ALL returned rows into a single array and then be able to do a sorted print from the array of ALL returned rows from db2?

Any other suggestions are welcome as well. Remember, I on doing a while loop on the returened hostname as that is the only way to gather the account_id (which i want to sort by).

Thanks in advance!!!!

Roy
 
If the account_id is unique just build a hash out of it with that as the key.

$data{$account_id} = $data;

then you can sort the hash as you print it.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top