RE: [PHP] splitting up an array into lines ...
| From: | Martin Towell | Date: | Tue, 15 Jan 2002 22:07:02 +0000 |
| Subject: | RE: [PHP] splitting up an array into lines ... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-80635@lists.php.net to get a copy of this message | ||
The problem is that this line:
$rpm_list =
rpm -qa;
gives back a string, so use this:
$rpm_list = rpm -qa;
$rpm_list = explode("\n", $rpm_list);
and see how that goes
Martin
-----Original Message-----
From: Neil Mooney [mailto:Neil.Mooney@cern.ch]
Sent: Wednesday, January 16, 2002 12:04 AM
To: php-general@lists.php.net
Subject: [PHP] splitting up an array into lines ...
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;
// open a db connection and insert them into the db
include "db.php";
print "working on host : $host\n";
$test = mysql_query ("SELECT * FROM machine_info WHERE host = '$host'");
$test1 = mysql_fetch_object ($test);
print "TEST: $test1->host\n";
if ($test1->host == "")
{
print "machine doesnt exists in the db , adding an entry for
$host\n";
$add_machine_to_table = mysql_query("INSERT INTO machine_info (host)
VALUES ('$host')");
}
// get the rpm list a line at a time
foreach($rpm_list as $rpm)
{
$query = "UPDATE machine_info SET rpm = '$rpm' WHERE host =
'$host'";
if (!(mysql_query($query)))
{
print "Mysql could not do the update query - for host
$host";
}
}
------------
i get :
X-Powered-By: PHP/4.0.6
Content-type: text/html
working on host : lxplus038
TEST: lxplus038
<br>
<b>Warning</b>: Invalid argument supplied for foreach() in <b>
get_rpm_info.php</b> on line <b>29</b><br>
--
many thanx in advance
Neil
:)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net