$_POST multiple entries from a list
Posted: Fri Jun 17, 2011 9:23 am
I have a php script that I run which queries a set of databases. At present all the possible databases are listed on a page (connections_array.php), along with their attributes similar to:
At the bottom of that page, I then group them together as I need a different set for different parts of the script.
I then refer to these groups when I need them. However, in order to remove a database (if it is malfunctioning, or offline for any amount of time) requires me to manually edit this file. So I wanted to add a section to my config page where I could select which databases were in which groups, and then save this back to my config database for the script to refer to when it starts (thus enabling other people to remove databases in my absence).
But then I got stuck.
So far I have created a page that contains a form, that lists all the databases, with a tick box underneath.
My plan was to POST the result back to the config page, and save the result to the database in the format of "1,2,3,6,7,8" using the dbID for the connections_array to refer to.
But this is where I run into problems, as I can't see a way to loop the incoming POST statement correctly, avoiding the need to write 80 POST statements on the receiving page (currently 20 databases listed x 4 groups).
Plus the dbID would be used 4 times, so I don't think I could actually refer to it anyway? Making it unique in the form (e.g. "sl_$dbID" = sl_01) would prevent me using to refer back to the original Array.
Any help / thoughts would be greatly appreciated.
Code: Select all
$db1_array[] = array('server' => '172.x.x.x:3306',
'user' => $u,
'password' => $p,
'database' => 'Master',
'sendmail' => '0',
'repeat' => '0',
'dbID' => '01'
);
Code: Select all
$master_array = array_merge ( (array)$db1_array,
(array)$db2_array,
(array)$db3_array
);
But then I got stuck.
So far I have created a page that contains a form, that lists all the databases, with a tick box underneath.
Code: Select all
<form name="ConfigDBList" id="DBList" action="configChange.php" method="Post" >
<?php
include ('connections_array.php');
print "SLAVE DATABASES (for check slave status queries)";
print "<table style=\"width:98%\">";
print "<tr>";
foreach($connections_array as $db) {
$dbname = $db['database'];
$dbid = $db['dbID'];
print "<td>$dbname</td>";
};
print "</tr><tr>";
foreach($connections_array as $db) {
$dbname = $db['database'];
$dbid = $db['dbID'];
print "<td><INPUT TYPE=\"checkbox\" NAME=\"$dbid\" VALUE=\"$dbname\"></td>" ;
};
print "</tr>";
print "</table>";
print "</br>";
//REPEAT THIS 4 TIMES FOR THE 4 GROUPS I NEED
?>
<p class="submit"><input type="submit"/></p>
</form>
But this is where I run into problems, as I can't see a way to loop the incoming POST statement correctly, avoiding the need to write 80 POST statements on the receiving page (currently 20 databases listed x 4 groups).
Plus the dbID would be used 4 times, so I don't think I could actually refer to it anyway? Making it unique in the form (e.g. "sl_$dbID" = sl_01) would prevent me using to refer back to the original Array.
Any help / thoughts would be greatly appreciated.