Read multiple arrays in mysql


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read multiple arrays in mysql
# 1  
Old 11-10-2008
Read multiple arrays in mysql in perl

I have a database that include 5 tables, and they are related to each other through foreign key relations. The root is called colleges. There are multiple colleges, and each college has 1+ departments, each department has 1+ IT stuff, each IT stuff owns 1+ IP addresses. I have designed the database hierarchically as: Colleges->Departments->ITstuff->IP. Each child has a foreign that points to it's parent.

My goal is to read IP addresses of each department and scan them, then send a report to all IT stuff to the departments as well as cc to the college IT director. My strategy is to read all college (using fetchrow_arrayref or whatever works), and save it in an array. Then for each college, search all departments, and save into another array. Next, search each department, and find all IP assoicated to the department and save into a list for scan. In the code I have come up so far, I'm stuck at where highlighted in red. Thanks in advance.

$myQuery = "select college_id from Colleges";
$mysth = &excuteQuery($mydbh, $myQuery);

#my (@colleges) = ();
while (my @ary = $mysth->fetchrow_array()){
push(@colleges, [@ary]); # [@ary] is a reference
$i++;
}
$mysth->finish();

$college_id;
$i = 0;
foreach(@colleges){
# print "colleges: ", @{colleges->[$i]}, "\n";
$college_id=@{colleges->[$i]};
$i++;
print "college id: ", $college_id, "\n";
$myQuery = "select d.departmentName from Colleges c join Departments d on c.college_id=d.college_id where c.college_id='$college_id'";
$deptsth = &excuteQuery($mydbh, $myQuery);
$j=0;
while (my @ary = $deptsth->fetchrow_array()){
push(@departments, [@ary]); # [@ary] is a reference
print "departments: ", @{departments->[$j]}, "\n";
$j++;
}
}$myQuery = "select college_id from Colleges";
$mysth = &excuteQuery($mydbh, $myQuery);

#my (@colleges) = ();
while (my @ary = $mysth->fetchrow_array()){
push(@colleges, [@ary]); # [@ary] is a reference
$i++;
}
$mysth->finish();

$college_id;
$i = 0;
foreach(@colleges){
# print "colleges: ", @{colleges->[$i]}, "\n";
$college_id=@{colleges->[$i]};
$i++;
print "college id: ", $college_id, "\n";
$myQuery = "select d.departmentName from Colleges c join Departments d on c.college_id=d.college_id where c.college_id='$college_id'";
$deptsth = &excuteQuery($mydbh, $myQuery);
$j=0;
while (my @ary = $deptsth->fetchrow_array()){
push(@departments, [@ary]); # [@ary] is a reference
print "departments: ", @{departments->[$j]}, "\n";
$j++;
}
}

Last edited by pinkgladiator; 11-10-2008 at 11:31 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating script with multiple job arrays

Hello everyone, First of all this is my first post and im fairly new to working with Unix and creating scripts etc. so there will probably be wrong phrases used. Lets get to my questions. I have multiple scripts that submit Slurms/Jobs to the cluster starting like this and doing certain... (3 Replies)
Discussion started by: idbemad
3 Replies

2. Programming

Looping through multiple arrays in C.

Not sure if this is possible, but I've tried this about a thousand ways now. I am making something with a lot of arrays. I thought I could put the array names into a separate array and then loop through them to call all of their elements. This is the best I've got so far: #include <stdio.h>... (4 Replies)
Discussion started by: Azrael
4 Replies

3. Shell Programming and Scripting

Compare multiple arrays elements using awk

I need your help to discover missing elements for each box. In theory each box should have 4 items: ITEM01, ITEM02, ITEM08, and ITEM10. Some boxes either have a missing item (BOX02 ITEM08) or might have da duplicate item (BOX03 ITEM02) and missing another one (BOX03 ITEM01). file01.txt ... (2 Replies)
Discussion started by: alex2005
2 Replies

4. Shell Programming and Scripting

Multiple arrays in variable using for loop

Hi, I'm trying to get the number of files inside same kind of folders on each disks and assigning each values in to a variable named with same folder and disk name so that it'll be easy for me to identify each time.But somehow I'm not able to assign those values in that specific name variable... (1 Reply)
Discussion started by: ratheeshp
1 Replies

5. Shell Programming and Scripting

Loop over multiple arrays

Hi All I need really really help with this :- I have two files ( File1 , File 2) both files are output of two different scripts. File1 usually has a list of names ( sometimes 3 names sometimes 5 sometimes more , depends about the output of the script) File2 usually has a list of numbers... (2 Replies)
Discussion started by: samsan
2 Replies

6. Shell Programming and Scripting

awk arrays comparing multiple columns across two files.

Hi, I'm trying to use awk arrays to compare values across two files based on multiple columns. I've attempted to load file 2 into an array and compare with values in file 1, but success has been absent. If anyone has any suggestions (and I'm not even sure if my script so far is on the right lines)... (4 Replies)
Discussion started by: hubleo
4 Replies

7. Web Development

mysql query for multiple columns from multiple tables in a DB

Say I have two tables like below.. status HId sName dName StartTime EndTime 1 E E 9:10 10:10 2 E F 9:15 10:15 3 G H 9:17 10:00 logic Id devName capacity free Line 1 E 123 34 1 2 E 345 ... (3 Replies)
Discussion started by: ilan
3 Replies

8. Shell Programming and Scripting

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP. I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies

9. UNIX for Advanced & Expert Users

multiple arrays through awk...

i am v new to awk, well unix as a whole really but im enjoying it alot... im trying to extract some data from a file, and parsing it into arrays, ive trawled for hours on the internet and cant find much when it comes to awk and arrays?? anyway, heres the file: tableA tableB tableC ... (2 Replies)
Discussion started by: newbeenie
2 Replies

10. Shell Programming and Scripting

Nested Loop to Echo Multiple Arrays

I have three arrays which hold three elements each. I have a fourth array which contains the names of those three arrays. I'm having difficulty creating a nested loop that can loop through each array and echo their values. script #!/bin/ksh # array of locations (usa, london, australia)... (1 Reply)
Discussion started by: yongho
1 Replies
Login or Register to Ask a Question