Page 1 of 1

Modifying an Array

Posted: Fri Aug 27, 2010 5:26 am
by IGGt
Hi Guys,

I have an array that contains a list of database's and associated data. My Php script then checks the databases for various situations and then sends an email if that situation is found. At present it works simply with a variable (if problem found 'set $var=1', then at the end of the loop 'if $var==1' send email).
But as the script updates every 60 seconds I was looking to reduce it by using $POST to pass $var across. But, as there are multiple databases, I was looking to incorporate $var into the array (and later on find a way of $POST the array - but that's for later).

The problem I have at the minute, is how to update the array.

So far I have:

Code: Select all

$connections_array[] = array('server' => 'localhost:3306',
                             'user' => $u,
                             'password' => $p,
                             'database' => 'MySQL01',
                             'sendmail' => '0'
                                           );

for($i = 0; $i <sizeof($connections_array); $i++) {

$connect to db etc. etc. etc.
while($row = mysql_fetch_assoc($result)) {
					if ($row['Slave_IO_Running'] == "No")
                                                {
						$connections_array[$i]['sendmail'] = '1');
						}
etc. etc. etc.

If ($connections_array[$i]['sendmail'] == 1)
          send email etc. etc.
But this results in a Parse error where I try to update the array.

So I was wondering what is the correct sytax to use when updating an Array element?

Re: Modifying an Array

Posted: Fri Aug 27, 2010 8:13 am
by IGGt
I spotted it, I had inadvertently left a bracket ')' at the end of the line. Once removed it all works fine again. Doh!