Results 11 to 15 of 15
-
24th Dec 2010, 06:50 PM #11MemberWebsite's:
litewarez.net litewarez.com triniwarez.comThe problem is that most programmers including the better ones will always do recursive calls to the database, causing higher load on the DB.
You can do this in a single pass, using PHP References.
Example:
PHP Code:$refs = array();
$list = array(); //This is the baby
$result = mysql_query("SELECT * FROM releases");
while($data = @mysql_fetch_assoc($result))
{
//Cfreate / Select a referenced variable in the memory
$thisref = &$refs[ $data['id'] ];
//Set the parent id
$thisref['parent'] = $data['parent'];
//Set the data as your going to need it later
$thisref['data'] = $data;
//If its not a root, set the referenced array
if ($data['parent'] == 0)
{
$list[ $data['id'] ] = &$thisref;
}
else
{
$refs[ $data['parent'] ]['children'][ $data['id'] ] = &$thisref;
}
}
The code above will replicate hierarchy in a PHPJoin Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
25th Dec 2010, 12:40 AM #12OPMember
Thanks very much! Wow, i'll take a look at this in a couple days and try to get my head around it.
Can you show an example for grandchildren? I'll perhaps get a better perspective.
EDIT: @dermechove Thanks that worked!
-
25th Dec 2010, 06:31 AM #13The Wise OneWebsite's:
twilight.ws ddlrank.comHey,
Yeah litewarez it's true, but still, we are working with someone who is learning PHP and therefor I didn't give him any code that he wouldn't understand.
I have been coding (not part of my job/uni) PHP for many years now and I never even used the '&' sign or anything
Anyways, just had a look at your code, and that would work too.I can always be contacted by sending a tweet @twilightws
-
25th Dec 2010, 06:38 AM #14Respected DeveloperWebsite's:
X4B.orgreferences are really ugly in the over all scheme of things. Usually they can be advoided and in this case it can by loading all the data from the table into an array to begin with and instead of querying the database looking it up in the hash table/array (key=>value).
In reality although your solution has better performance litewarez, Whoo's is better for the skill level of the OP.
-
25th Dec 2010, 11:44 AM #15MemberWebsite's:
litewarez.net litewarez.com triniwarez.comReferences are not ugly, if i used a custom class for storing the data they would be passed by reference anyways as of PHP5
References allow control over the data in the memory, as your referencing data and not creating new ones.
This is a new technique that should be used as standard, if he is new to PHP, should we not teach him the best possible solution regardless weather its its slightly more demanding for a newbie ?Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
E-Mail Can Reveal Your Friend Hierarchy
By Daniel in forum News & Current EventsReplies: 0Last Post: 30th Nov 2011, 08:19 PM -
Porn Forum List "add your list"
By Mr-Egy in forum Webmaster DiscussionReplies: 3Last Post: 15th Jul 2011, 11:11 AM -
Rank Hierarchy Icons
By gmaister22 in forum Webmaster DiscussionReplies: 8Last Post: 27th Feb 2011, 06:29 PM -
List of ips what spam/ddos - Please add yours if you have a list
By Sp32 in forum Webmaster DiscussionReplies: 23Last Post: 3rd Jul 2009, 04:07 AM
themaLeecher - leech and manage...
Version 5.03 released. Open older version (or...