?
Solved

Need help with this array

Posted on 2006-05-08
12
Medium Priority
?
209 Views
Last Modified: 2010-03-05
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.
0
Comment
Question by:bneese
  • 6
  • 3
9 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 16634531
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;
0
 

Author Comment

by:bneese
ID: 16635200
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...
0
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 16635291
I was thinking of something like

                while(@abc=$sth->fetchrow_array)
                {
                       my %h;
                        @h{qw((Class) (Attribute))}=@abc;
                          push @databasevalues,%h;
                }
                $sth->finish;
                $admindb->disconnect;
               print "@databasevalues";

Does that produce anything like what you want?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:bneese
ID: 16638944
yes, now how can I print each line of the array individually? Thanks
0
 

Author Comment

by:bneese
ID: 16638973
actually its printing like this:

(Attribute) Caption (Class) win32_bios

can I get it like this instead?

(Class) win32_bios (Attribute) Caption
0
 

Author Comment

by:bneese
ID: 16638984
Never mind the last post. But I do want to print each line in the array individually
0
 
LVL 85

Expert Comment

by:ozo
ID: 16639069
                while(@abc=$sth->fetchrow_array)
                {
                       print "(Class) $abc[0] (Attribute) $abc[1]<br />\n";
                }
                $sth->finish;
                $admindb->disconnect;
0
 

Author Comment

by:bneese
ID: 16639228
maybe I don't understand. I want to print what is in the array after the data has gotten in it?
0
 

Author Comment

by:bneese
ID: 16639254
I want to do a foreach class.value in the array query WMI. Maybe that will help...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question