close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Inserting multiple selections from list/menu

Thread began 9/08/2009 3:21 am by dallySP | Last modified 5/11/2019 6:56 pm by Ray Borduin | 8246 views | 43 replies |

dallySP

Inserting multiple selections from list/menu

Hi,
I'm creating an items_Insert page for an online clothes store. I want the customer to be able to search for clothes by occasion. I've created a table called Occasions with 2 fields (OccasionID and OccasionName) and a dynamic list/menu that allows multiple selections (one item may be suitable for working wardrobe or smart/casual for example). I want the OccasionName(s) to be inserted into the items table under 'ItemOccasion' as a comma separated list. Could you let me how I need to adjust the insert code to all for this.

Sign in to reply to this post

Jason ByrnesWebAssist

first, make sure the name of the select list ends with "[]", for example:
name="select[]"

When you bind the column to the select list, DataAssist will add code similar to:

php:
<?php echo((isset($_POST["select[]"]))?$_POST["select[]"]:""?>




change that to use the implode() function to convert the array to a coma separated list:

php:
<?php echo((isset($_POST["select"]))?implode(", "$_POST["select"]):""?>
Sign in to reply to this post

dallySP

Thats great - thank you for that. Just one other thing - on the update page is there a way to bring the list up preselected, otherwise if you don't reselect the items it knocks them out of the database.

Sign in to reply to this post

Jason ByrnesWebAssist

This is a bit more difficult.


When it comes out of the recordset, you will need to convert the coma separated list back into an array using the explode() function, and use the in_array() function to determine in the checked value for each check box is in the array.


For example:

php:
<input type="checkbox" name="CheckboxGroup1[]" value="1" id="CheckboxGroup1_0" <?php if(isset($row_RecordsetName['ColumnName']) && is_array($row_RecordsetName['ColumnName'])) {
  if(
in_array("1"$row_RecordsetName['ColumnName'])) echo("checked=\"checked\"");
}
?> />
Sign in to reply to this post

dallySP

OK - I'm struggling with this a bit. On my update page I've got a series of checkboxes created dynamically for the rsOccasions recordset. I've mimicked your code as follows:

<input type="checkbox" name="Occasions[]" value="<?php echo $row_rsOccasions['OccasionName']; ?>"
<?php if(isset($row_rsOccasions['OccasionName']) && is_array($row_rsOccasions['OccasionName'])) {
if(in_array($row_rsOccasions['OccasionName'], $row_rsOccasions['OccasionName'])) echo("checked=\"checked\"");
}
?>

Could you let me know if this is correct and what code I need for the explode function and where to put it.
Thanks.

Sign in to reply to this post

Jason ByrnesWebAssist

change this peace:
in_array($row_rsOccasions['OccasionName'], $row_rsOccasions['OccasionName'])


to:
in_array($row_rsOccasions['OccasionName'], explode(", ", $row_rsOccasions['OccasionName']))

Sign in to reply to this post

dallySP

I think I must have a syntax error somewhere as I'm getting this error message:

Parse error: parse error, unexpected T_ECHO in C:\wamp\www\okeefe\public_html\admin\items_Update.php on line 296

The code I've got is as follows:

<input type="checkbox" name="Occasions[]" value="<?php echo $row_rsOccasions['OccasionName']; ?>"
<?php if(isset($row_rsOccasions['OccasionName']) && is_array($row_rsOccasions['OccasionName'])) {
if(in_array($row_rsOccasions['OccasionName'], explode(", ", $row_rsOccasions['OccasionName'])) echo("checked=\"checked\"");
}
?> />

Sign in to reply to this post

Jason ByrnesWebAssist

try this code:
<input type="checkbox" name="Occasions[]" value="<?php echo $row_rsOccasions['OccasionName']; ?>"
<?php if(isset($row_rsOccasions['OccasionName']) && is_array($row_rsOccasions['OccasionName'])) {
if(in_array($row_rsOccasions['OccasionName'], explode(", ", $row_rsOccasions['OccasionName']))) echo("checked=\"checked\"");
}
?> />

Sign in to reply to this post

dallySP

Thats got rid of the error code - sorry that was me being a bit dim. Update page still doesn't come back with the relevant check boxes checked through. Is there anything else I might be missing?

Sign in to reply to this post

Jason ByrnesWebAssist

My turn to be a bit dim.


I forgot to explode the recordset into an array in the is_array() check.


Third times a charm, try this code:

php:
<input type="checkbox" name="Occasions[]" value="<?php echo $row_rsOccasions['OccasionName']; ?>"

<?php if(isset($row_rsOccasions['OccasionName']) && is_array(explode(", "$row_rsOccasions['OccasionName']))) {
if(
in_array($row_rsOccasions['OccasionName'], explode(", "$row_rsOccasions['OccasionName']))) echo("checked=\"checked\"");
}
?> />
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...