close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Checkbox value & Relational Table

Thread began 11/10/2010 5:58 pm by dan361748 | Last modified 11/15/2010 1:07 pm by Jason Byrnes | 3197 views | 10 replies |

dan361748

Checkbox value & Relational Table

Hi - I'm trying to send a checkbox value to a relational table. I think the relational part is working right, as it pre-selects my form. This is the second form on my page though. Anyway - can I send the checkbox value like this?

<input <?php if (!(strcmp($row_chapters['CHAP_ID'],WA_AB_returnPreSelectValue($WA_PreSelect_RelationalTable_1, $row_chapters['CHAP_ID'])))) {echo "checked=\"checked\"";} ?> name="CHAP_ID_<?php echo $RepeatSelectionCounter_1; ?>" type="checkbox" id="CHAP_ID_<?php echo $RepeatSelectionCounter_1; ?>" value="<?php echo $row_chapters["CHAP_ID"]; ?>" />

Thanks

Sign in to reply to this post

tom92909Beta Tester

I did something similar to that very thing today...



I'm using DataAssist to Update the record...

php:
$WA_connection = $dbconnect;

  $WA_table = "consultants";
  $WA_redirectURL = "";
  $WA_keepQueryString = false;
  $WA_indexField = "consultant_rec_id";
  $WA_fieldNamesStr = "fname|lname|title|emailaddress|password|status|group|phone_number";
  $WA_fieldValuesStr = "".((isset($_POST["fname"]))?$_POST["fname"]:"")  ."" . "|" . "".((isset($_POST["lname"]))?$_POST["lname"]:"")  ."" . "|" . "".((isset($_POST["title"]))?$_POST["title"]:"")  ."" . "|" . "".((isset($_POST["email_address"]))?$_POST["email_address"]:"")  ."" . "|" . "".((isset($_POST["password"]))?$_POST["password"]:"")  ."" . "|" . "".((isset($_POST["status"]))?$_POST["status"]:"")  ."" . "|" . "".((isset($_POST["group"]))?$_POST["group"]:"")  ."" . "|" . "".((isset($_POST["phone"]))?$_POST["phone"]:"")  ."";
Sign in to reply to this post

dan361748

Thanks Tom

I think I need to use the relational table because the check boxes that contain the ID value are in a repeat selection, plus they need to pre-select when the form loads.

My main table is manuals
My option table is chapters
My relational table is map_mc

It's funny - the preselect portion works fine (the form loads with the current relational table data pre-selected), but when I submit my form the relational table behaviour just deletes the records with the main table ID (MANUAL_ID) rather than updating/adding them. It makes me the form is not passing along the option table id (CHAP_ID) and may have something to do with the way I have my checkbox values set up, but I'm stuck.

Sign in to reply to this post

tom92909Beta Tester

I'm not sure, but I would recommend looking into using JOIN on your manuals & chapters tables on unique ID numbers.

Is that possible? Will that help? or am I missing what you're trying to accomplish?

Sign in to reply to this post

dan361748

Thank you for your help Tom.

Doesn't the Manage Relational Table behaviour function handle the creation of the query and the JOIN?

I've attached my page - I hope that isn't presumptuous. Just so you know what I am looking at.

Attached Files
admin_Manuals_Update.php.zip
Sign in to reply to this post

tom92909Beta Tester

LOL, I'll have to look into that Doh! I guess I'm still doing things the old way.

I'm manually creating my JOIN in my recordset.

SELECT clients.consultant_id, clients.client_rec_id, consultants.consultant_rec_id, consultants.fname, consultants.lname
FROM clients JOIN consultants ON consultants.consultant_rec_id = clients.consultant_id
WHERE client_rec_id = colname



The colname Variable is defined to receive the rec_id from a GET ( $_GET['id'] )

Sign in to reply to this post

dan361748

Thanks Tom - yes I am talking about the Manage Relational Table behaviour.

The behaviour won't post my values. It will only delete the records that match the MANUAL_ID.

Any other suggestions?

Sign in to reply to this post

dan361748

Tried a blank page - still no work

As a follow up to this I thought I would try the behaviour on a blank page and the problem is the same.

The behaviour deletes the corresponding records that match the MANUAL_ID key in the relational table. I'm convinced this has to do with no value being passed from the checkbox, however if I view the source the value appears correct. Here is my page:

<?php require_once('Connections/boomcms.php'); ?>
<?php require_once("WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_boomcms, $boomcms);
$query_manual = "SELECT * FROM manuals WHERE MANUAL_ID = 6";
$manual = mysql_query($query_manual, $boomcms) or die(mysql_error());
$row_manual = mysql_fetch_assoc($manual);
$totalRows_manual = mysql_num_rows($manual);

mysql_select_db($database_boomcms, $boomcms);
$query_chapters = "SELECT * FROM chapters";
$chapters = mysql_query($query_chapters, $boomcms) or die(mysql_error());
$row_chapters = mysql_fetch_assoc($chapters);
$totalRows_chapters = mysql_num_rows($chapters);?>
<?php
// WA DataAssist Manage Relational Table 1
if ($_SERVER["REQUEST_METHOD"] == "POST") // Trigger
{
$WA_arrayOrFieldList = 1;
$WA_joinLoopedField = "CHAP_ID";
$WA_loopedField = "WADA_RepeatID_CHAP_ID";
$WA_connection = $boomcms;
$WA_table = "map_mc";
$WA_redirectURL = "";
$WA_keepQueryString = false;
$WA_masterKeyField = "MANUAL_ID";
$WA_masterKeyType = "none,none,NULL";
$WA_masterKeyValue = "".$row_manual['MANUAL_ID'] ."";
$WA_masterKeyComp = "=";
$WA_joinedKeyField = "CHAP_ID";
$WA_joinedKeyType = "none,none,NULL";
$WA_joinedKeyComp = "=";
$WA_fieldNamesStr = "MANUAL_ID|CHAP_ID";
$WA_columnTypesStr = "none,none,NULL|none,none,NULL";
$WA_appliedString = "";
$WA_appliedList = array();
$WA_valuesList = array();
$WA_connectionDB = $database_boomcms;
mysql_select_db($WA_connectionDB, $WA_connection);
if ($WA_arrayOrFieldList == 0) {
$WA_loopedValues = $_POST[$WA_joinLoopedField];
for ($v=0; $v<sizeof($WA_loopedValues); $v++) {
$WA_fieldValues = "^MASTERID^" . "|" . "^JOINID^";
$WA_valuesList[] = array($WA_loopedValues[$v], $WA_fieldValues);
$WA_appliedString .= "^" . $WA_loopedValues[$v] . "^";
$WA_appliedList[] = $WA_loopedValues[$v];
}
}
else if ($WA_arrayOrFieldList == 1) {
$WA_mrtLoopCounter = 0;
while (WA_AB_checkLoopedFieldsExist(array($WA_loopedField), $WA_mrtLoopCounter)) {
if (WA_AB_checkLoopedFieldsNotBlank(array($WA_joinLoopedField), $WA_mrtLoopCounter) && WA_AB_getLoopedFieldValue($WA_loopedField, $WA_mrtLoopCounter) == WA_AB_getLoopedFieldValue($WA_joinLoopedField, $WA_mrtLoopCounter)) {
$WA_fieldValues = "^MASTERID^" . "|" . "^JOINID^";
$WA_valuesList[] = array(WA_AB_getLoopedFieldValue($WA_loopedField, $WA_mrtLoopCounter), $WA_fieldValues);
$WA_appliedString .= "^" . WA_AB_getLoopedFieldValue($WA_loopedField, $WA_mrtLoopCounter) . "^";
$WA_appliedList[] = WA_AB_getLoopedFieldValue($WA_loopedField, $WA_mrtLoopCounter);
}
$WA_mrtLoopCounter++;
}
}
WA_AB_doManageRelationalTable($WA_valuesList, $WA_appliedString, $WA_appliedList, $WA_connection, $WA_table, $WA_masterKeyField, $WA_masterKeyType, $WA_masterKeyValue, $WA_masterKeyComp, $WA_joinedKeyField, $WA_joinedKeyType, $WA_joinedKeyComp, $WA_fieldNamesStr, $WA_columnTypesStr);
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>
<?php
// WA DataAssist Pre-Select Relational Table 1
$WA_PreSelect_RelationalTable_1 = array();
$WA_connection = $boomcms;
$WA_table = "map_mc";
$WA_masterKeyField = "MANUAL_ID";
$WA_masterKeyType = "none,none,NULL";
$WA_masterKeyValue = "".$row_manual['MANUAL_ID'] ."";
$WA_masterKeyComp = "=";
$WA_joinedKeyField = "CHAP_ID";
$WA_connectionDB = $database_boomcms;
mysql_select_db($WA_connectionDB, $WA_connection);
$WhereObj = WA_AB_generateWhereClause(array($WA_masterKeyField), array($WA_masterKeyType), array($WA_masterKeyValue), array($WA_masterKeyComp));
$WA_Sql = "SELECT ".$WA_masterKeyField.", ".$WA_joinedKeyField." FROM ".$WA_table." WHERE ".$WhereObj->sqlWhereClause." ORDER BY ".$WA_joinedKeyField;
$WA_mrtJoinRS = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
if (mysql_num_rows($WA_mrtJoinRS) > 0) {
while ($row_WA_mrtJoinRS = mysql_fetch_assoc($WA_mrtJoinRS)) {
$WA_PreSelect_RelationalTable_1[] = $row_WA_mrtJoinRS[$WA_joinedKeyField];
}
}
?>
<?php
// RepeatSelectionCounter_1 Initialization
$RepeatSelectionCounter_1 = 0;
$RepeatSelectionCounterBasedLooping_1 = false;
$RepeatSelectionCounter_1_Iterations = "1";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="manualschapters" name="manualschapters" method="post" action="admin_Manuals_Grouping.php">
<?php
// RepeatSelectionCounter_1 Begin Loop
$RepeatSelectionCounter_1_IterationsRemaining = $RepeatSelectionCounter_1_Iterations;
while($RepeatSelectionCounter_1_IterationsRemaining--){
if($RepeatSelectionCounterBasedLooping_1 || $row_chapters){
?>
<table border="0" cellspacing="0" cellpadding="0">
<?php do { ?>
<tr>
<td><?php echo $row_chapters['CHAP_TITLE']; ?></td>
<td><label>
<input type="hidden" name="WADA_RepeatID_CHAP_ID_<?php echo $RepeatSelectionCounter_1; ?>" id="WADA_RepeatID_CHAP_ID_<?php echo $RepeatSelectionCounter_1; ?>" value="<?php echo $row_chapters["CHAP_ID"]; ?>" />
<input <?php if (!(strcmp($row_chapters["CHAP_ID"],WA_AB_returnPreSelectValue($WA_PreSelect_RelationalTable_1, $row_chapters["CHAP_ID"])))) {echo "checked=\"checked\"";} ?> <?php if (!(strcmp($row_chapters['CHAP_ID'],WA_AB_returnPreSelectValue($WA_PreSelect_RelationalTable_1, $row_chapters['CHAP_ID'])))) {echo "checked=\"checked\"";} ?> type="checkbox" id="CHAP_SELECT_<?php echo $RepeatSelectionCounter_1; ?>" name="CHAP_SELECT_<?php echo $RepeatSelectionCounter_1; ?>" value="<?php echo $row_chapters['CHAP_ID']; ?>" />
</label></td>
</tr>
<?php } while ($row_chapters = mysql_fetch_assoc($chapters)); ?>
</table>
<?php
} // RepeatSelectionCounter_1 Begin Alternate Content
else{
?>
<td>No records match your request.</td>
<?php } // RepeatSelectionCounter_1 End Alternate Content
if(!$RepeatSelectionCounterBasedLooping_1 && $RepeatSelectionCounter_1_IterationsRemaining != 0){
if(!$row_chapters && $RepeatSelectionCounter_1_Iterations == -1){$RepeatSelectionCounter_1_IterationsRemaining = 0;}
$row_chapters = mysql_fetch_assoc($chapters);
}
$RepeatSelectionCounter_1++;
} // RepeatSelectionCounter_1 End Loop
?>
<input name="SUBMIT" type="submit" value="SUBMIT" />
</form>
</body>
</html>
<?php
mysql_free_result($manual);

mysql_free_result($chapters);
?>

Any WA would be really appreciated. I can see a lot of uses for this behaviour, but am having trouble making it work. I can't use a list in this case as I intend on doing an order function on this table as well.

Sign in to reply to this post

Jason ByrnesWebAssist

Try changing:

php:
<?php } while ($row_chapters mysql_fetch_assoc($chapters)); ?>



to:

php:
<?php $RepeatSelectionCounter_1++; ?>

<?php 
} while ($row_chapters mysql_fetch_assoc($chapters)); ?>




If that doesn't work, i'll start a private ticket to get more information from you.

Sign in to reply to this post

dan361748

Hi Jason - thank you - I inserted the code and it still does not work. It just deletes the records that match the MANUAL_ID.

Please let me know if you are able to open a ticket. I've attached the page here.

Thanks

Attached Files
admin_Manuals_Grouping.php.zip
Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...