close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Current value for Multiple Select Menu

Thread began 2/29/2012 3:46 pm by md262153 | Last modified 3/01/2012 9:41 am by md262153 | 813 views | 2 replies |

md262153

Current value for Multiple Select Menu

I changed a Menu to multiple select (and yes, added [] to the select value). My problem is, in Update, it's not pulling in existing selection(s). Here's the code:

<select name="category[]" size="5" multiple="multiple" id="category">
<?php
do {
?>
<option value="<?php echo $row_WADADynListcompanies_type['name']?>"<?php if (!(strcmp($row_WADADynListcompanies_type['name'], $row_WADAcompanies["category"]))) {echo "selected=\"selected\"";} ?>><?php echo $row_WADADynListcompanies_type['display']?></option>
<?php
} while ($row_WADADynListcompanies_type = mysql_fetch_assoc($WADADynListcompanies_type));
$rows = mysql_num_rows($WADADynListcompanies_type);
if($rows > 0) {
mysql_data_seek($WADADynListcompanies_type, 0);
$row_WADADynListcompanies_type = mysql_fetch_assoc($WADADynListcompanies_type);
}
?>
</select>


- What am I missing here?

THANKS

===> ADDITIONAL INFORMATION
I see that DataAssist isn't storing the data properly in the db when I INSERT a new record (and I'm sure when I UPDATE). It's putting the word "Array" in the db instead of the array itself. What to do? What to do...?

===> FURTHER UPDATE
I can easily change the Update page to insert the correct information into the db field using IMPLODE. In the Application Builder section I changed $_POST["category"] to implode(",",$_POST["category"]) and it inserts a comma separated list into the db field as I want. Now the problem is....how do I get the Update page to display those as selected in a multiple select field?

Sign in to reply to this post

Jason ByrnesWebAssist

in the code that creates the list, you need to use the explode() and in_array() function to convert the comma seperated list back into an array and check if the current list item is in that array.

in your previous post, you give the following code for writing the list options:

php:
<option value="<?php echo $row_WADADynListcompanies_type['name']?>"<?php if (!(strcmp($row_WADADynListcompanies_type['name'], $row_WADAcompanies["category"]))) {echo "selected=\"selected\"";} ?>><?php echo $row_WADADynListcompanies_type['display']?></option>





you would need to change that to:

php:
<option value="<?php echo $row_WADADynListcompanies_type['name']?>"<?php if(isset($row_WADAcompanies["category"]) && is_array(explode(", "$row_WADAcompanies["category"]))) { 

if(
in_array($row_WADADynListcompanies_type['name'], explode(", "$row_WADAcompanies["category"]))) echo(" selected=\"selected\""); 

?>><?php echo $row_WADADynListcompanies_type['display']?></option>
Sign in to reply to this post

md262153

Beautiful! I had to get rid of a space in two places [explode(", ",)] but it works a charm. The only "problem" is it's actually a pretty bad way to handle this on an update page as it turns out, since all you need to do is click on one other option wanting to add it but not holding down Ctrl and you'd better hope you remember the original options!

But it works a charm.

THANKS!

Sign in to reply to this post

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