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

Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1.     
    #1
    Member

    Default PHP List Hierarchy


    Can you suggest how I output these to an expanding/collapsing hierarchy?

    Example: http://jqueryui.com/demos/accordion/
    Although the accordian is great, it wont work unless I output the html correctly which i'm finding very hard to do.

    Here is the page with my current code: http://filewi.re/releases.php

    And the code itself: http://code.google.com/p/filewire/so...s/releases.php

    This is hours of mental torture so it's a lil messy. Thanks.
    theforumdrunk Reviewed by theforumdrunk on . PHP List Hierarchy http://lulzimg.com/i02/13ed837b.png Can you suggest how I output these to an expanding/collapsing hierarchy? Example: http://jqueryui.com/demos/accordion/ Although the accordian is great, it wont work unless I output the html correctly which i'm finding very hard to do. Here is the page with my current code: http://filewi.re/releases.php And the code itself: http://code.google.com/p/filewire/source/browse/trunk/includes/releases.php Rating: 5

  2.   Sponsored Links

  3.     
    #2
    The Wise One
    Website's:
    twilight.ws ddlrank.com
    First of all you have your query above the table:
    PHP Code: 
    $get mysql_query("SELECT * FROM releases ORDER BY whateveryouwant"); 
    To be honest you should just put the table structure in plain HTML, and then within the <table> where you normally put each <tr> you just add something like this:

    PHP Code: 
    <table>
    // Head of the table like ID, name, etc goes here
    <?php
    while($row mysql_fetch_object($get)){
    ?>
    <tr>
    <td><?php echo $row->id?></td>
    <td><?php echo $row->name?></td>
    ...
    </tr>
    <?php 
    }
    ?>
    </table>
    Remember, try and keep as much HTML as you can, keep the design separated from the functionality. No need to go and display HTML in within a PHP echo function , just the stuff you need
    I can always be contacted by sending a tweet @twilightws

  4.     
    #3
    Member
    Thanks whoo, no problem with that. It's more the actual process of finding who belongs to whos parent (check db pic). Then displaying them in the right higherarchy.

  5.     
    #4
    The Wise One
    Website's:
    twilight.ws ddlrank.com
    It's just a matter of thinking:

    First you have to select all the parents, then for each parent, you print it, grab the children and print them too...

    And after that you just do like I told you:
    PHP Code: 
    <table>
    // Head of the table like ID, name, etc goes here
    <?php
    $get 
    mysql_query("SELECT * FROM tablename WHERE parent = 0 ORDER BY whateveryouwant");
    while(
    $parent mysql_fetch_object($get)){
      
    $get2  mysql_query("SELECT * FROM tablename WHERE parent = $parent->id ORDER BY whateveryouwant");
    ?>
    <tr>
    <td><?php echo $parent->id?></td>
    <td><?php echo $parent->name?></td>
    </tr>
    <?php
      
    while($child mysql_fetch_object($get2)) {
    ?>
    <tr>
    <td><?php echo $child->id?></td>
    <td><?php echo $child->name?></td>
    ...
    </tr>
    <?php 
    }
    ?>
    </table>
    This should display

    -Parent1
    --Child
    --Child
    --Child
    -Parent2
    --Child
    --Child
    --Child


    Hope this helped
    I can always be contacted by sending a tweet @twilightws

  6.     
    #5
    Member
    This is SO much cleaner.
    Reckon you could post an example for a third level? That is a "Grandchild".

  7.     
    #6
    The Wise One
    Website's:
    twilight.ws ddlrank.com
    Sure, just name how many children you want, this script is horny

    PHP Code: 
    <table>
    // Head of the table like ID, name, etc goes here
    <?php
    $get 
    mysql_query("SELECT * FROM tablename WHERE parent = 0 ORDER BY whateveryouwant");
    while(
    $parent mysql_fetch_object($get)){
      
    $get2  mysql_query("SELECT * FROM tablename WHERE parent = $parent->id ORDER BY whateveryouwant");
    ?>
    <tr>
    <td><?php echo $parent->id?></td>
    <td><?php echo $parent->name?></td>
    </tr>
    <?php
      
    while($child mysql_fetch_object($get2)) {
        
    $get3 mysql_query("SELECT FROM tablename WHERE parent = $child->id ORDER BY whateveryouwant");
    ?>
    <tr>
    <td><?php echo $child->id?></td>
    <td><?php echo $child->name?></td>
    ...
    </tr>
    <?php
    while($grandchild mysql_fetch_object($get3)){
    ?>
    <tr>
    <td><?php echo $grandchild->id?></td>
    <td><?php echo $grandchild->name?></td>
    ...
    </tr>
    <?php ?>
    <?php 
    }
    ?>
    </table>
    I hope you get how this works now
    I can always be contacted by sending a tweet @twilightws

  8.     
    #7
    Member
    DOH! Why didn't I think of this

    Thanks bro, you're a legend!

  9.     
    #8
    The Wise One
    Website's:
    twilight.ws ddlrank.com
    Quote Originally Posted by theforumdrunk View Post
    DOH! Why didn't I think of this

    Thanks bro, you're a legend!
    It was a pleasure...

    I wish you good luck and don't forget that perseverance is the key to success when coding something
    I can always be contacted by sending a tweet @twilightws

  10.     
    #9
    Member
    Saves making another thread.
    The code is updated and looks as it should. http://code.google.com/p/filewire/so...s/releases.php

    If the function in that class is called it should be outputting nothing as I clear the buffer at the end but save it to a variable. However, it has no effect and outputs everything: http://filewi.re/releases.php (You should be seeing a blank page)

    Please tell me how this is possible

  11.     
    #10
    Member
    Website's:
    ExpresShare.com
    use ob_get_contents() instead.
    ob_get_flush outputs to the browser the saved buffer+ save it to a sting.

Page 1 of 2 12 LastLast

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