Jane,
I finally found the php code and generator to accomplish my main objective outlined in my initial posting.
The method of managing checkboxes as is suggested/implemented in phprunner is not ideal as explained at the URL below:
http://jpipes.com/index.php?/archives/33-Managing-Many-to-Many-Relationships-in-MySQL-Part-1.html
The ideal method of saving and retrieving selected checkbox items is by using a connector or mapping table to manage the many-to-many relationship between mysql tables.
Unfortunately, phprunner does not presently use nor suggests this method in its documentation. Hopefully, this will be addressed in future releases.
Anyway, I found this amazing website generates the php code that easily manages selected items from a checkbox
http://phpcode.hu/teszt/checkbox_expert/
Below is the code that I generated for myself. You will see that code is pretty simple and effective. It also implements the many-to-many relationship via the recommended connector/mapping table. Now I just have massage the code to get it work within phprunner.
<code>
<?php
session_start();
// Save this file into phpconnect.php file
// This file generated by http://phpcode.hu/teszt/checkbox_expert/
// Please leave this message if you post the generated code on forums, or sell this program
/*
You don't need to run the table create SQL code, if you already have the 3 tables.
/
// / For the following details,
// / please contact your server vendor
$hostname = 'xxxxxxxx'; //// specify host, i.e. 'localhost'
$user = 'xxxxxxxx'; //// specify username
$pass = 'xxxxxxxx'; //// specify password
$dbase = 'xxxxxxxx'; //// specify database name
$connection = mysql_connect( "$hostname" , "$user" , "$pass" )
or die ( "Can't connect to MySQL" );
$db = mysql_select_db( $dbase , $connection ) or die ( "Can't select database." );
$table1 = "users"; //this table will be listed
$idfield1 = "user_id";
$filename="phpconnect.php";
/ many relations/
$idfield2 = "hobby_id";
$table2 = "hobbies";
$fieldname_2 = "name";
/ connector table to handle many properties/
$conntablename = "user2hobby";
$connector_id1 = "user_id";
$connector_id2 = "hobby_id";
print "<a href=\"$filename\">List</a><br />";
if ( !empty( $_POST["id"] ) ) {
$sql = sprintf( "delete from $conntablename WHERE $connector_id1=%d" , $_POST["id"] );
$res = mysql_query( $sql );
if ( !empty( $_POST["ch"] ) ) {
foreach( $_POST["ch"] AS $ids ) {
$sql = sprintf( "insert into $conntablename ($connector_id1,$connector_id2) VALUES('%d','%d')" , $_POST["id"] , $ids );
$res = mysql_query( $sql );
}
}
unset( $sql );
header( sprintf( "Location: $filename?edit=%d&ok=1", $_POST["id"] ) );
}
if ( isset( $_GET["edit"] ) ) {
if ( isset( $_GET["ok"] ) )
print "Updated succesfully<br />";
$sql2 = sprintf( "
SELECT $idfield2
,$fieldname_2
,if($table2.$idfield2 IN (select $connector_id2 from $conntablename where $conntablename.$connector_id1 =%d),1,0) AS is_in FROM $table2
;
" , $_GET["edit"] );
// print $sql2."<br />";
print '<form method="post" action="'.$filename.'">';
print "<input type=\"hidden\" name=\"id\" value=\"" . $_GET["edit"] . "\">";
$result = mysql_query( $sql2 );
while ( $rows = mysql_fetch_assoc( $result ) ) {
$checked = empty( $rows["is_in"] )?"":" checked=\"checked\"";
echo "<input type=\"checkbox\" name=\"ch[]\" value=\"{$rows["$idfield2"]}\"$checked>{$rows["$fieldname_2"]}<br />";
}
print '<input type="submit" name="submit" value="submit">';
print "</form>";
die();
}
$query = "select from $table1";
$result = mysql_query( $query ) or die("Error in mysql query:" . mysql_error());
?>
<table width="520" border="1">
<tr>
<th align="center" valign="top" bgcolor="#CCCCCC" scope="col">Properties</th>
<th align="center" valign="top" bgcolor="#CCCCCC" scope="col">Firstname</th>
<th align="center" valign="top" bgcolor="#CCCCCC" scope="col">Lastname</th>
<th align="center" valign="top" bgcolor="#CCCCCC" scope="col">Email</th>
</tr>
<?php
if ( mysql_num_rows( $result ) > 0 ) {
while ( $one_row = mysql_fetch_assoc( $result ) ) {
print '<tr>';
?>
<th align="center" valign="top" bgcolor="#CCCCCC" scope="col"> <a href="?edit=<?php echo $one_row[$idfield1];
?>">Edit</a> </th>
<td align="center" valign="top"><?php echo !empty( $one_row["firstname"] )? htmlspecialchars( $one_row["firstname"] ):" "; ?></td>
<td align="center" valign="top"><?php echo !empty( $one_row["lastname"] )? htmlspecialchars( $one_row["lastname"] ):" "; ?></td>
<td align="center" valign="top"><?php echo !empty( $one_row["email"] )? htmlspecialchars( $one_row["email"] ):" "; ?></td>
</tr>
<?php
}
print '</table>';
} else
print "</table>no result";
/ End of listing/
/
--
-- Table structure for the connector table table user2hobby
--
CREATE TABLE user2hobby
(
user_id
int(11) NOT NULL,
hobby_id
int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Table structure for (second) table hobbies
--
CREATE TABLE hobbies
(
hobby_id
int(11) NOT NULL auto_increment,
name
varchar(255) NOT NULL,
PRIMARY KEY (hobby_id
)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
--
-- Table structure for table users
--
CREATE TABLE users
(
user_id
int(11) NOT NULL auto_increment,
firstname
varchar(255) NOT NULL,
lastname
varchar(255) NOT NULL,
email
varchar(255) NOT NULL,
PRIMARY KEY (user_id
)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
/
?>
</code>