Pull down (multi value) - Get options from database

9 posts by 3 authors in: Forums > CMS Builder
Last Post: December 17, 2010   (RSS)

By ryanGT - November 22, 2010

Hi,

Im having some troubles with extracting the multi-value results from on of my fields in the CMSB.

Basically I am trying to create a for each loop that for every value in the multi-value pull down it publishes the relevant youtube video.

I already have the embed code working for a static video, but need to make it dynamic so the user can add multiple videos to the system.

If you know a better way of doing this, or can help me out that would be grand!

thanks
Ryan

Re: [Jason] Pull down (multi value) - Get options from database

By ryanGT - November 24, 2010

Hi,

Thanks for that, but I'm still having some troubles.

Would you be able to provide me with an example page? I'm fairly new to PHP programming, I have searched through other posts to see if I can solve the issue myself, but to no avail.

Kind regards

Ryan

Re: [ryanGT] Pull down (multi value) - Get options from database

By Jason - November 24, 2010

Hi Ryan,

It may be difficult to give a good example since you're trying to accomplish something specific. If you could attach the .php file you're working with, I can take a look at that.

Also, please let me know the name of the mult-value field you're working with and exactly what is being stored there.

Once I have this, I should be able to give you a more specific example of how to do this.

Thanks.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Pull down (multi value) - Get options from database

By ryanGT - November 26, 2010

Hi Jason,

I have attached the PHP file that I am working with.

The name of the multi-value is 'youtube_video_url'

This field then links to a table or section called 'cms_youtube_videos' and has two fields called 'title' and 'youtube_video_id'

I am not interested in displaying the title of the youtube videos, just the youtube video id. I was then going to create a for each loop and wrap the video id's into the youtube video embed code.

If there is anything else that you need, let me know

Kind regards

Ryan
Attachments:

gsu-draft.php 4K

Re: [ryanGT] Pull down (multi value) - Get options from database

By Jason - November 26, 2010

Hi Ryan,

Try something like this:

<?php
$youtube_videos = trim($gsu_draftRecord['youtube_video_url'],"\t");
$youtube_videos = explode("\t",$youtube_videos);
?>

<?php foreach($youtube_videos as $videoId):?>
**OUTPUT VIDEO HERE**
<?php endforeach ?>


In your foreach loop, the variable $videoId is the value field of your multi-select drop down.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Pull down (multi value) - Get options from database

By Rusty - December 17, 2010 - edited: December 17, 2010

So based upon what you've told me, if I want to submit a form with multiple values selected, hard coded, I would use your / CMSB /t switch.


Ah HA~!!

You mention how to strip the tabs out, with trim and explode.

What if I wanted to go the other direction?

I noticed another switch used on the errorsAndAlerts the \n switch, what's that one do?

So I'm thinking that this might work setting/putting Multiple Values INTO the Database from a form.


mysql_query("INSERT INTO `{$TABLE_PREFIX}accounts` SET
state = '".mysql_escape("Ohio\tPennsylvania")."',


?? Just wondering.
Rusty

Re: [Rusty] Pull down (multi value) - Get options from database

By Jason - December 17, 2010

Hi Rusty,

You're close. You need to have a tab character at the beginning and end of the string as well:

mysql_query("INSERT INTO `{$TABLE_PREFIX}accounts` SET
state = '".mysql_escape("\tOhio\tPennsylvania\t")."',


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Pull down (multi value) - Get options from database

By Rusty - December 17, 2010 - edited: December 17, 2010

Hi Rusty,

You're close. You need to have a tab character at the beginning and end of the string as well:

mysql_query("INSERT INTO `{$TABLE_PREFIX}accounts` SET
state = '".mysql_escape("\tOhio\tPennsylvania\t")."',


Hope this helps



I was sooo close. I was just thinking to myself, huh, wonder if I need to wrap tabs around the entire bit, like a container.

[]bWorks like a charm!, I had been able to play around with it to the point where I could get multiple options selected, but not the proper values, my values had 'around' them, extra single quotes from me doing silly stuff like ("'Ohio'/t'Pennsylvania'") and so on.

Just further proof I need to keep plowing ahead full steam in my PHP studies. I love this stuff, it's so flexible! and powerful.

If I'm ever up in the other Vancouver, I definitely owe you guys a round of the ale/beverage of choice.

Thanks again for world class support.!
Rusty