close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Manage relational tables with two key fields

Thread began 6/01/2009 9:18 pm by office377308 | Last modified 10/18/2010 6:15 am by Ray Borduin | 3200 views | 6 replies |

office377308

Manage relational tables with two key fields

I ahve put a similar question before, but here it seems even more relevant: I have a relational table, consisting of only two fields:
foreign key a and foreign key b pointing to table products (key a) and categories (key b).
In my case I setup the structure so that both fields form the key. I attach a phpmyadmin screenshot. How can I use this with MRT?

Sign in to reply to this post

russell355191Beta Tester

2 key fields

Hi,
I noticed that you made them both primary keys. I don't think that'll work. Because your PK's are in the other 2 tables.

If you remove both primary keys, click on the relation view icon just above the index area and use the "link to" and link them to your PK's in the other tables you'll have just index keys on your 2 table items.

I think you need to make the tables innoDB as well, but not sure about that.

Regards

Russ

Sign in to reply to this post

I-CRE8Beta Tester

On your update products page where I assume you will be using the MRT SB you would pass the product id using the id value returned in your recordset and then pass the value for categories from a select list, here is some code from a previous project that used this logic:

<?php
// WA DataAssist Manage Relational Table 1
if (isset($_POST["update_x"])) // Trigger
{
$WA_arrayOrFieldList = 0;
$WA_joinLoopedField = "assocCat";
$WA_loopedField = "";
$WA_connection = $connDB;
$WA_table = "lnk_product_category";
$WA_redirectURL = "view-product.php?prodID=".((isset($_POST["prodID"]))?$_POST["prodID"]:"") ."";
$WA_keepQueryString = false;
$WA_masterKeyField = "prodID";
$WA_masterKeyType = "none,none,NULL";
$WA_masterKeyValue = "".$row_rsProducts['prodID'] ."";
$WA_masterKeyComp = "=";
$WA_joinedKeyField = "catID";
$WA_joinedKeyType = "none,none,NULL";
$WA_joinedKeyComp = "=";
$WA_fieldNamesStr = "prodID|catID";
$WA_columnTypesStr = "none,none,NULL|none,none,NULL";
$WA_appliedString = "";
$WA_appliedList = array();
$WA_valuesList = array();
$WA_connectionDB = $database_connDB;
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);
}
}
?>



A couple of explanations might be in order

$WA_joinLoopedField = "assocCat"; is the select list containing the categories
$WA_table = "lnk_product_category"; is my database table set up like yours (see attached screenshot)
$WA_masterKeyValue = "".$row_rsProducts['prodID'] .""; is the product ID recordset value

you should be able to work out everything else from there.

Sign in to reply to this post

office377308

it does work now

Originally Said By: russell355191
  Hi,
I noticed that you made them both primary keys. I don't think that'll work. Because your PK's are in the other 2 tables.

If you remove both primary keys, click on the relation view icon just above the index area and use the "link to" and link them to your PK's in the other tables you'll have just index keys on your 2 table items.

I think you need to make the tables innoDB as well, but not sure about that.

Regards

Russ  



Thank you for your reply. You made good points.
But my idea was:
It is necessary to have them both defined (together) as primary keys because only each pair must be unique. I wonder if this option will be implemented in DA one day? I learned this trick from osCommerce which is an open source webshop soulution with some real good options.

Sign in to reply to this post

Ray BorduinWebAssist

I don't see why it wouldn't work. Where are you getting stuck?

Sign in to reply to this post
Did this help? Tips are appreciated...

ken413883

I am having the exact same issue...

I have a table that has 3 fields, 2 of which are FK's to other tables and those to FK's as a pair must be unique, so they are both set to primary key...which works great in all other parts of the site.

However, I am trying to now set up and update screen for the 3rd field, and I can't figure out how to pass both primary keys as variables to the update page.

Is there a way to force DA to use 2 fields as primary key? If not, what code do I enter/modify on the update page (which is all I really need) to pull the correct result?

Example:

People = FK to People Table - PK
Profession = FK to Profession Table - PK
Salary = requires update fields


A single person may have multiple professions, and each profession has a different salary range associated with it - by the same token, multiple people could have the same professions, and have different salary range(s) than other folks in that profession...

When someone clicks the link on the Person Detail page (which will point to the update salary page for that profession) I need to make sure it pulls the correct person and the correct profession so they can edit the appropriate salary line...

I don't really have any code to attach, because I can't figure out how to complete the DA Wizard with 2 primary keys...

Help?

Sign in to reply to this post

Ray BorduinWebAssist

If you are using mySQL 5+ you could create a view that concatinates the two keys into a single unique key. DataAssist is designed to only work with a single key, but by concatinating the two keys you should be able to create a single unique key.

Sign in to reply to this post
Did this help? Tips are appreciated...

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...