We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Multi Drop-down List

Development and Programming

Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

Huh, thanks.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen

Hi Mark,

Sorry to re-open this post as it were. Just wanted to say a massive thanks for such a great extension but I was just wondering if anyone could help with a slight problem I have. The problem is nothing to do with your extension but more a way that I would like to use the data that has been entered by it.

When I use the multi drop down menu in an entry it adds in the ‘entry_id’s’ of the items I am selecting into the exp_weblog_data field. This is all fine. What I need to be able to do is to use a PHP MySQL query (not within EE) so that I can make the PHP file as a totally standalone file which is what I need for what I am doing.

The data inside the field that your extension is inputting is like this :

102 104 105 106 112

etc..

Your extension is putting in the entry_id’s with a return / newline between them. What I need to be able to do is to bring back these numbers which I can do with a simple SELECT query but then I need to be able to perform queries using each of the entry_id’s contained in that field. So for example I would first of all bring back the field contents as above and then I would like to be able to explode (I think that’s the correct term) each of these numbers so that they can each be used in a SQL query to spit out another answer.

So for example :

SELECT field_id_44
FROM exp_weblog_data
WHERE entry_id = '3'

This will bring back

102
104
105
106
112

I would then like to be able to run another SQL query multiple times using each of the numbers in it. So :

SELECT field_id_46
FROM exp_weblog_data
WHERE entry_id = '102' AND weblog_id = '7'

Next run the same query on the next number

SELECT field_id_46
FROM exp_weblog_data
WHERE entry_id = '104' AND weblog_id = '7'

I can then spit out data each time to do what I need to do.

The part I am having problems with is getting the data that is in the multi drop down field and exploding it into its separate number parts.

If anyone understands any of this and could possibly lend a hand with this then I would be exceptionally grateful.

Thank you in advance.

Best wishes,

Mark

       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

Yup. I’ve done this several times and here’s what I’ve found to be the most effective. First return your data in the parent entry, so like you have something like this:

SELECT field_id_46
FROM exp_weblog_data
WHERE entry_id = '102' AND weblog_id = '7'

Then using PHP split that data into an array. To do this there are several methods, personally I like to use preg_split (but i’m sure explode() and split() would also work) and split on both newlines and carriage returns. I split on both (even though the extension uses only carriage returns) just in case someone uses phpMyAdmin to edit the MySQL, since it seems to use newlines not carriage returns. So that said, our code now looks something like this:

$query = mysql_query("SELECT field_id_46 AS children FROM exp_weblog_data WHERE entry_id=102 AND weblog_id=7");
$result = mysql_fetch_object($query);
$children = preg_split("/[\r\n]/+", $result->children);

Now we have our children entries in an array and we can simply place them back in another MySQL query like so:

$query = mysql_query("SELECT entry_title FROM exp_weblog_titles WHERE entry_id IN(".implode(",", $children).")");

Using that you can loop through all your returned results. I’ve compiled this below:

$query = mysql_query("SELECT field_id_46 AS children FROM exp_weblog_data WHERE entry_id=102 AND weblog_id=7");
$result = mysql_fetch_object($query);
$children = preg_split("/[\r\n]/+", $result->children);
$query = mysql_query("SELECT url_title, title FROM exp_weblog_titles WHERE entry_id IN(".implode(",", $children).")");
while($result = mysql_fetch_object($query))
{
    // -- Individual entry processing here.  Something like:
    // -- echo '<li><a >url_title.'" title="'.$result->title.'">'.$result->title.'</a></li>';
}
       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen

Hi Mark,

Thanks for the reply!!

Haven’t had chance to try out your code yet as I did actually get it all working in the end but using a whole heap more code than yours!! Was just about to post here and then I saw this. Will give it a go as soon as I get the chance. If it works the way I need it to, which I’m sure that it will then you will save me quite a few lines of code!!

Thanks for everything. Please let me know if there is ever anything I can do to help you out in any way at all.

Speak to you soon.

Best wishes,

Mark

       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

If you’re using this extension in combination with any of my other extensions it is highly recommended that you update all of them or field data may not enter correctly. You can find links to the individual posts below:

Checkbox: http://ellislab.com/forums/viewthread/38843/ Multi Drop-down List: http://ellislab.com/forums/viewthread/38370/ Multi Text: http://ellislab.com/forums/viewthread/39153/ File: http://ellislab.com/forums/viewthread/38997/

Or you can find a list of them on my docs page: http://docs.markhuot.com

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen

Hi Mark,

Thanks for the links. I did actually download them from that page already so hopefully everything should be up to date already. Sure this will help others out though.

Thanks again for absolutely fantastic extensions and modules. A real class act!!

Best wishes,

Mark

       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

I’ve just updated them a few minutes ago, so just compare the version number in the PHP file with the _ext on the zip file to make sure you’ve got this last update.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
18 years ago
Ryan M.'s avatar Ryan M.

That Multi-Drop Down list alone saved me hours last night. WOW was that handy. Thanks for all your work, Mark.

       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

Ok, another update. This one is specifically aimed at using the extension as a form of tagging. Place an option in the list (under the admin tab » blog admin » custom fields) named {input} and the publish screen will now have a simple text input below the select box. Entering content into that box and hitting return will select items in the list, or if they aren’t in the list add them through ajax (which means you’ll have to have JS enabled to use this feature).

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen

Hi Mark,

Thanks for that. Very useful indeed. Is it possible to get this working if the list is created using the ‘Populate the menu from another custom field’?

That would be really great as at the moment I am having to select items from a VERY long list and this would help absolutely no end.

Any help with this would be great. Thanks!

Best wishes,

Mark

       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

Mark: obviously the field wouldn’t allow you to add new entries (because it’s coming from an entirely different weblog), however there probably is the possibility for a type ahead search field when viewing options from another custom field. In fact I know I’ve done this before, I just have to dig it out of the depths of subversion and get it working again. I’ll let you know how it goes.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen

Hi Mark,

That would be great if you could do that thanks!

Best wishes,

Mark

       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

hi mark, check it out - multi relationships: http://ellislab.com/forums/viewthread/39595/

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen

Hi Mark,

Thanks for that. Taking a look right now. As always fantastic work from yourself.

Best wishes,

Mark

       
Mark Huot's avatar
Mark Huot
587 posts
18 years ago
Mark Huot's avatar Mark Huot

Sorry about that Mark. I’m not sure why I posted that to you directly, but for some reason I thought you asked me for the multi-relation field.

       
1 2 3 4 Last

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.