Activity Stream
48,167 MEMBERS
6818 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15
  1.     
    #11
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    The 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;
        }

    Example of why references works is like so:



    The code above will replicate hierarchy in a PHP
    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


  2.   Sponsored Links

  3.     
    #12
    Member
    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!

  4.     
    #13
    The Wise One
    Website's:
    twilight.ws ddlrank.com
    Quote Originally Posted by litewarez View Post
    The problem is that most programmers including the better ones will always do recursive calls to the database, causing higher load on the DB.
    Hey,

    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

  5.     
    #14
    Respected Developer
    Website's:
    X4B.org
    references 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.

  6.     
    #15
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    References 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.


    Quote Originally Posted by Whoo View Post
    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 .
    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


Page 2 of 2 FirstFirst 12

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. E-Mail Can Reveal Your Friend Hierarchy
    By Daniel in forum News & Current Events
    Replies: 0
    Last Post: 30th Nov 2011, 08:19 PM
  2. Porn Forum List "add your list"
    By Mr-Egy in forum Webmaster Discussion
    Replies: 3
    Last Post: 15th Jul 2011, 11:11 AM
  3. Rank Hierarchy Icons
    By gmaister22 in forum Webmaster Discussion
    Replies: 8
    Last Post: 27th Feb 2011, 06:29 PM
  4. Replies: 23
    Last Post: 3rd Jul 2009, 04:07 AM

Tags for this Thread

BE SOCIAL