close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Help with some code, please

Thread began 5/16/2012 1:33 pm by msummers194171 | Last modified 5/25/2012 10:30 am by msummers194171 | 2278 views | 11 replies |

msummers194171

Help with some code, please

I have a select tag on an update page created using DataBridge and I want it to load showing the properly selected value from the database. It's not doing that.

The code is this:

<option value="">Select Project Category</option>
<?php
do {
?>
<option value="<?php echo $row_WADAproject['project']?>"<?php if (!(strcmp($row_WADAproject['project'], (isset($_GET["invalid"])?ValidatedField("projectsupdate","project"):"".$row_WADAprojects["project"]."")))) {"selected=\"selected\"";} ?>><?php echo $row_WADAproject['project']?></option>
<?php
} while ($row_WADAproject = mysql_fetch_assoc($WADAproject));

Basically, I need you to explain this code and how it works.

How should I change that code so that the selected="selected" is properly shown when the original value/validated value equals the current value of $row_WADAproject['project']?

Sign in to reply to this post

Jason ByrnesWebAssist

send a copy of the page so i can see the code in context please. i need to see the recordsets being created as well as the list code.

Sign in to reply to this post

msummers194171

Thanks, Jason....

Attached Files
projects_update.zip
Sign in to reply to this post

Jason ByrnesWebAssist

this is a badly set up page and a badly set up database.

it looks like you are trying to store it looks like your select list is a multiple select list which would mean that projects are stored as a comma separated list to the database.

this is a bad practice. this is not the correct way to create a many to many relationship


your project categories should be in it;s own table:
categories:
categorieID - primary key
categoriesName - varchar

the categories table should be used to populate the list.

Should the category select list be a multiple select List? or should a project belong to only 1 category?

If the project should belong to only 1 category, then you can use a standard insert to the products table, and store the category ID.

if a project can belong to more than 1 category, then you are trying to create a many to many relationship, and will need a 3rd linking table:

projectcategories:
projectcategorieID - primary key
projectcategorieProjectID - relates to project.id
projectcategorieCategoryID - relates to categories.categorieID

and you will need to use the manage relational table behavior to assign the categories to projects.

Sign in to reply to this post

msummers194171

Originally Said By: Jason Byrnes
  this is a badly set up page and a badly set up database.

it looks like you are trying to store it looks like your select list is a multiple select list which would mean that projects are stored as a comma separated list to the database.

this is a bad practice. this is not the correct way to create a many to many relationship  



Nope, that's not how it is at all.

The projects records each include a project category field as an enum field. I have a recordset on that page that does a SELECT DISTINCT on that field - thus, the recordset ($row_WADAProject) thus contains a single instance of each project category. This recordset is used only to populate that select tag. As I'm stepping through that recordset I want to compare each project category to the category in the record specified by the passed ID, and when they match, add the "selected" attribute to the associated <option> tag.

Each project in the projects table will belong only to a single project category.

Does that help you understand what I am doing? I want a list of categories with the category applicable to the given record already selected.

Sign in to reply to this post

Jason ByrnesWebAssist

I have created a support ticket so we can look into this issue further.

To view and edit your support ticket, please log into your support history:
supporthistory.php

If anyone else is experiencing this same issue, please append to this thread.

Sign in to reply to this post

msummers194171

Thank you, Jason.

Sign in to reply to this post

msummers194171

Jason - under the general subject of 'help with some code', can you please explain to me this line of code? It's taken from a radio button group created with DB:

if (array_search("1", ((isset($_GET["invalid"]) && ValidatedField("projectsupdate","display"))?ValidatedField("projectsupdate","display"):array())) !== false

My interpretation of this is the following - just tell me if I am correct.

When a field fails validation, the form needs to know whether to display the data in the database or the newly submitted data as the page refreshes and to do that the form submits to itself with a url variable of "invalid". So that line is testing whether it's the current field that failed validation or not (in this case that field is named 'display'). If it did fail validation, then the database data is shown, and if it did not fail validation then the (valid) submitted data is shown. I think I have that right....

What puzzles me is that the false part of the ternary operator is just an empty array. Why is that?

So, breaking it down:

isset($_GET['invalid']) - this is true when there is a field in the posted data that fails validation.

ValidatedField("projectsupdate","display") - I'm not exactly sure what this does, but it's always null for this 'display' field.

in this case, these two tests both fail, meaning that the ternary isset($_GET["invalid"]) && ValidatedField("projectsupdate","display"))?ValidatedField("projectsupdate","display"):array() will always return (for this particular field) the "false" result, i.e., array(). But that array is completely empty!

Since the array is empty, the test array_search("1",array()) will always fail, and so 'checked="checked"' will never get written. And this is in fact the case - that radio group is not populated when the update page loads.

My conclusion is that an empty array at that point is an error. I don't know whether it's my error (although I haven't hacked this part of the code at all) or DB's error.

Sorry this is so long-winded, but it will sure help me understand the code to get your thoughts....

Sign in to reply to this post

Jason ByrnesWebAssist

  ValidatedField("projectsupdate","display") - I'm not exactly sure what this does, but it's always null for this 'display' field.  




the validated entries collection returns any valid form data when the form fails validation.

you assessment of the code is correct, though I think it would only be using an array search for a multiple select list, or checkbox group, not for a radio group which can only ever have one item checked.

Sign in to reply to this post

msummers194171

Jason: It seems that would be the case for a radio group, but I have just verified on a test page that this is the way the code is inserted - a blank array - when you create a DA form with only a radio group. Please try that - it must be a bug.

In fact, I can make that block of code work by inserting a single value into that empty array:

ValidatedField("projectsupdate","display"):array($row_WADAProjects['display'])))

With that code, the radio group is shown properly populated whether its value is yes or no.

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