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!

multidimensional array creation problem`

Status
Not open for further replies.

willyd61

MIS
May 6, 2003
37
US
Hey Guys, I am not very good at creating multi-dim arrays, What I am doing is doing a query, returning query results into a array, then for looping the next query based on the 1st array like so: (return_array is just all the oci stuff returning a array back)

$sql = "SELECT DISTINCT(WEBREQUESTCLASS) FROM aradmin.helpdeskproblemtype WHERE WEBREQUESTCLASS is not NULL";
$main = return_array($sql);
foreach($main as $test) {
$sql = "SELECT DISTINCT(WEBREQUESTCATEGORY) from helpdeskproblemtype where webrequestclass = '$test'";
$stmt = ociparse($con,$sql);
ociexecute($stmt);
$nrows = OCIFetchStatement($stmt,$results);
if ( $nrows > 0 ) {
while ( list( $key, $val ) = each( $results ) ) {
//print "$key";
}
for ( $i = 0; $i < $nrows; $i++ ) {
reset($results);
while ( $column = each($results) ) {
$data = $column['value'];
print "$test:$data[$i]\n";
}
}
}
}
print_r($return_array);

***********************************************************
Doing a print_r returns this:

Database:
Software Application:Crystal Enterprise
Software Application:Oracle Applications
Software Application:Remedy
Software Application:Visionael
UK Software Application:Crystal Enterprise
UK Software Application:Remedy
UK Software Application:Visionael

***********************************************************

If I were to write this by hand I would want like so:

$main[0] = "Software Application";
$main[1] = "Server";
$main[2] = "Network Device";
$main[3] = "Database";
$secondary[0][0] = "Crystal Enterprise";
$secondary[0][1] = "Remedy";
$secondary[0][2] = "Visionael";
$secondary[0][3] = "BUCS";
$secondary[1][0] = "Unix";
$secondary[1][1] = "Windows";
$secondary[2][0] = "IP Device";
$secondary[2][1] = "SS7 Device";
$secondary[2][2] = "X.25 Device";
$secondary[3][0] = "Oracle";
$secondary[3][1] = "SQL Server";
$secondary[3][2] = "MYSQL";
***********************************************************

Note all this data is not complete, just wanted to show snippets.... So basically the 2nd array is the multi array with the 1st element being the string from the 1st array... make sense???

Please Help!!
 
I was looking at my post, and thought it might be easier to simplify the question.

I have one array built from a query, say like this...

$main = array('foo','bar','test','one');

I then do a foreach($main as $i) {
$sql = "select blah from blah where columna = '$i';
)

This is going to return groups of records that I want to produce a multi array. Like so

$multi = array(foo=>1,
foo=>2,
bar=>a,
test=>z,
);

this is how I did it by hand before I was using the DB to create.

$main[0] = "Software Application";
$main[1] = "Server";
$main[2] = "Network Device";
$main[3] = "Database";
$secondary[0][0] = "Crystal Enterprise";
$secondary[0][1] = "Remedy";
$secondary[0][2] = "Visionael";
$secondary[0][3] = "BUCS";
$secondary[1][0] = "Unix";
$secondary[1][1] = "Windows";
$secondary[2][0] = "IP Device";
$secondary[2][1] = "SS7 Device";
$secondary[2][2] = "X.25 Device";
$secondary[3][0] = "Oracle";
$secondary[3][1] = "SQL Server";
$secondary[3][2] = "MYSQL";


This is going to be the input for a hierselect from the pear module quick_form.







-Willy D
 
Jeez, my bad... Here is the output I need.........

1st query give me array $main, then I my and clause finds the records that would associate.

<?php
$main[0] = "Application";
$main[1] = "Server";
$main[2] = "Network Device";
$main[3] = "Database";
$secondary[0][0] = "Crystal Enterprise";
$secondary[0][1] = "Remedy";
$secondary[0][2] = "Visionael";
$secondary[0][3] = "BUCS";
$secondary[1][0] = "Unix";
$secondary[1][1] = "Windows";
$secondary[2][0] = "IP Device";
$secondary[2][1] = "SS7 Device";
$secondary[2][2] = "X.25 Device";
$secondary[3][0] = "Oracle";
$secondary[3][1] = "SQL Server";
$secondary[3][2] = "MYSQL";
print_r($secondary);
?>


**************************
Here is the result that I want to recreate...

Array
(
[0] => Array
(
[0] => Crystal Enterprise
[1] => Remedy
[2] => Visionael
[3] => BUCS
)

[1] => Array
(
[0] => Unix
[1] => Windows
)

[2] => Array
(
[0] => IP Device
[1] => SS7 Device
[2] => X.25 Device
)

[3] => Array
(
[0] => Oracle
[1] => SQL Server
[2] => MYSQL
)

)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top