Link to home
Start Free TrialLog in
Avatar of bneese
bneese

asked on

Need help with this array

I am building an array using a MySQL query:

$sql = "SELECT `win32attributes`.`Class`,`win32attributes`.`Attribute`,`win32attributes`.`Status`
FROM `win32attributes`
Inner Join `win32classes` ON `win32classes`.`ClassName` = `win32attributes`.`Class`
WHERE `win32classes`.`Status` = '1' AND `win32attributes`.`Status` = '1'";
                $sth = $admindb->prepare($sql);
                $sth->execute();
                while(@abc=$sth->fetchrow_array)
                {
                    for($i=0;$i<@abc;$i++)
                    {  
                        $databasevalues[$i+$counter] = $abc[$i];
                        $counter += $i;
                    }
                }
                $sth->finish;
                $admindb->disconnect;
                print "@databasevalues";
}

The output is something like like this except its on one line:

win32_bios Caption  
win32_bios Description  
win32_quickfixengineering Description  
win32_quickfixengineering FixComments  
win32_quickfixengineering HotFixID  
win32_quickfixengineering InstalledBy  
win32_quickfixengineering Name  
win32_quickfixengineering ServicePackInEffect

Is there a way to add the column names in the db like this:

(Class)win32_bios (Attribute)Caption
(Class)win32_bios (Attribute)Description  
(Class)win32_quickfixengineering (Attribute)Description  
(Class)win32_quickfixengineering (Attribute)FixComments  
(Class)win32_quickfixengineering (Attribute)HotFixID  
(Class)win32_quickfixengineering (Attribute)InstalledBy  
(Class)win32_quickfixengineering (Attribute)Name  
(Class)win32_quickfixengineering (Attribute)ServicePackInEffect

I want to be able to call this array and query WMI on each item in the array.
Avatar of ozo
ozo
Flag of United States of America image

What is this loop intended to do?
                    for($i=0;$i<@abc;$i++)
                    {  
                        $databasevalues[$i+$counter] = $abc[$i];
                        $counter += $i;
                    }
Did you mean something like
  push @databasevalues,@abc;
or
  my %h;
  @h{qw((Class) (Attribute))}=@abc;
  push @databasevalues,%h;
Avatar of bneese
bneese

ASKER

I actually got this code from someone else. If there is a better way to do this I am open to suggestions. Would I get rid of the loop? Would it look like this?

$sql = "SELECT `win32attributes`.`Class`,`win32attributes`.`Attribute`,`win32attributes`.`Status`
FROM `win32attributes`
Inner Join `win32classes` ON `win32classes`.`ClassName` = `win32attributes`.`Class`
WHERE `win32classes`.`Status` = '1' AND `win32attributes`.`Status` = '1'";
                $sth = $admindb->prepare($sql);
                $sth->execute();
                while(@abc=$sth->fetchrow_array)
                {
                    for($i=0;$i<@abc;$i++)
                    {  
                       my %h;
                        @h{qw((Class) (Attribute))}=@abc;
                          push @databasevalues,%h;
                   }
                }
                $sth->finish;
                $admindb->disconnect;
                print "@databasevalues";
}

I want to take each record in the array and use it to query WMI like this:

Select (Attribute)Caption FROM (Class)win32_bios

something like that...
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bneese

ASKER

yes, now how can I print each line of the array individually? Thanks
Avatar of bneese

ASKER

actually its printing like this:

(Attribute) Caption (Class) win32_bios

can I get it like this instead?

(Class) win32_bios (Attribute) Caption
Avatar of bneese

ASKER

Never mind the last post. But I do want to print each line in the array individually
                while(@abc=$sth->fetchrow_array)
                {
                       print "(Class) $abc[0] (Attribute) $abc[1]<br />\n";
                }
                $sth->finish;
                $admindb->disconnect;
Avatar of bneese

ASKER

maybe I don't understand. I want to print what is in the array after the data has gotten in it?
Avatar of bneese

ASKER

I want to do a foreach class.value in the array query WMI. Maybe that will help...