Array Help |
[eluser]Clauddiu[/eluser]
Hey guys, I have a problem with some arrays, I'm new to php and codeigniter. I want to have a function in my model that can simulate a relation between some tables. So I have this array Code: $_users = array( and I want to make it look like this: Code: $_users = array( I can't find a way of doing this, I always get duplicates because I have to check the with array, the with array will tell me what tables will be related. Can anyone please give me a hint how to do this, please? Regards, Claudiu
[eluser]jmadsen[/eluser]
This is a case where I think it is best to ask, "Why are you doing this?" before answering, because it seems like using sql joins in your query or something similar would be much better. I would answer that question before jumping on any response people might give about how to do a bunch of iterations. Php-wise, it is simple, but probably a really bad solution. I have a feeling you might be dealing with this issue? http://www.codebyjeff.com/blog/2012/08/n...rscore-php
[eluser]Clauddiu[/eluser]
Yes, I use a database to make this happen like this: Code: $test = db::table('admin')->relate( I'm using Idiorm with some custom methods, anyways all you see is based on $_with array which comes from related method, right there I get the related tables. So what I need is how the heck to make this recursive work without having duplicates, or any a better solution, please let me know. Regards, Claudiu
[eluser]jmadsen[/eluser]
I've never worked with Idiorm, but if it is giving you a single result set that you need reworked like you described, that blog post I put up is exactly what you want. Unfortunately my host just went down for an hour or so of scheduled maintenance :-( It is using Underscore.php's groupby function: http://brianhaveri.github.com/Underscore.php/ -- if you can wait an hour, you can see exactly how to set it up in CodeIgniter, or just have a go from the docs
[eluser]Clauddiu[/eluser]
Sure, no problem at all. I'll wait, lemme know when I can read your article. Thank you.
[eluser]jmadsen[/eluser]
actually, google was nice enough to cache it http://webcache.googleusercontent.com/se...=firefox-a |
Welcome Guest, Not a member yet? Register Sign In |