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
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>';
}
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
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
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).
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: 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.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.