On Tuesday 15 January 2002 21:04, Neil Mooney wrote:
> I want this code to work thru a large cluster and put the rpm information
> into a db ,
> it all works apart from the foreach loop.
> why doesnt my code work ( in particular the foreach loop ) ,
> // get hostname
> $host = `hostname`;
> // get a list of rpms
> $rpm_list = `rpm -qa`;
> foreach($rpm_list as $rpm)
> $query = "UPDATE machine_info SET rpm = '$rpm' WHERE host =
> if (!(mysql_query($query)))
> print "Mysql could not do the update query - for host
> i get :
> X-Powered-By: PHP/4.0.6
> Content-type: text/html
> working on host : lxplus038
> TEST: lxplus038
> <b>Warning</b>: Invalid argument supplied for foreach() in <b>
> get_rpm_info.php</b> on line <b>29</b><br>
That's telling you that $rpm_list is not an array. The output of `rpm -qa` is
just a string (with \n for newlines).
Thus to change $rpm_list into an array just do:
$rpm_list = explode("\n", $rpm_list);
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
(1) Giving away baby clothes and furniture is the major cause
(2) Always be backlit.
(3) Sit down whenever possible.
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]