close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

how can I optimize this...

Thread began 4/10/2009 12:30 pm by akstudio | Last modified 4/10/2009 3:38 pm by Ray Borduin | 2554 views | 4 replies |

akstudio

how can I optimize this...

I have a form.

I have 3 tables in a db. (assecories, products, lookup)

in my form, I have 14 check boxes. you can select more than 1. This information goes into the lookup. The code is as follows:

<?php
// WA Application Builder Insert
if ($_SERVER["REQUEST_METHOD"] == "POST") // Trigger
{
$WA_connection = $connNews;
$WA_table = "lookup";
$WA_sessionName = "lookup_accessory_ID";
$WA_redirectURL = "";
$WA_keepQueryString = false;
$WA_indexField = "accessory_ID";
$WA_fieldNamesStr = "accessory_ID|product_ID";
$WA_fieldValuesStr = "".$_SESSION['accessories_accessory_ID'] ."" . "|" . "".((isset($_POST["duo"]))?$_POST["duo"]:"") ."";
$WA_columnTypesStr = "',none,''|',none,''";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_connNews;
mysql_select_db($WA_connectionDB, $WA_connection);
if (!session_id()) session_start();
$insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id();
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);
}
}
?>


This line is question is:


$WA_fieldValuesStr = "".$_SESSION['accessories_accessory_ID'] ."" . "|" . "".((isset($_POST["duo"]))?$_POST["duo"]:"") ."";


I thought I could just duplicate this 14 times. Doest work

Do I have to do a "DataAssist>>insert record" 13 more times? I would think there is a way to optimize this.

thanks

Sign in to reply to this post

Ray BorduinWebAssist

Is this for a lookup table? You should be using "Manage relational Table" instead of insert and it will loop on the checked values for you.

Otherwise I suppose you could apply it thirteen times or write a while loop by hand around it.

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

akstudio

I get this error when trying to insert "manage relational table"

---------------------------
You must have a multi-select or fields within a repeated region to use this interface.
---------------------------

I'm using check boxes.

Sign in to reply to this post

akstudio

This doest make sense to me, I have encased my table (which containes 14 check boxes) within a repeat region. All that does is repeat the table 14 times, giving me a total of 196 check boxes.

following the pdf tutorial, I understand that, if you wanted to add 5 users at a time, then this makes sense. However, I have 1 form where a "product accessory" is added into the db. This form must also associate this new "product accessory" with an already existing product on the market. Therefore, these 14 check boxes must end up in the lookup table, and the rest of the form goes to the accessories table.

The repeat region seems to... well...repeat a region, but I think I need a loop or something.

I do have all this working fine, but it will only write the first checkbox.... unless, of course, I insert 13 more 'insert record' statements.

Sign in to reply to this post

Ray BorduinWebAssist

You should only have one checkbox inside the repeat region. The value of the checkbox should be set to the id in the database and you should get the label from the database as well.

This way you would have 14 unique checkboxes, one for each row in the database and if you add more rows to the database, the correct corresponding row would appear in your interface.

That is the concept of the relational table and the one to many relationship... that you have one table of values you want to insert into another table and maintain a relationship to a third. I think this is what you want, but you need to start by creating your form dynamically as you have kind of started to do.

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