Jump to content

Recommended Posts

Hey guys!

I am currently working on an unlimited tree list that is taking for ever to load ... takes abbout 30 secondes ...

My client created a list with over 2500 items going up to 5 of profound.

 

My code is simple ... this is what i made:

 

function page_enfant($parent, $level = 1)
{
    $select_page_enfant = mysql_query("SELECT * FROM pages WHERE parent ='$parent' order by ordre asc") or die(mysql_error());
    if(mysql_num_rows($select_page_enfant)!='')
    {
        $selectparent = mysql_fetch_array(mysql_query("SELECT * FROM pages WHERE id='$parent'"));
        echo '<ul>';
        while ($list_page_enfant = mysql_fetch_array($select_page_enfant)) {
         
        $selectparent = mysql_fetch_array(mysql_query("SELECT * FROM pages WHERE id='$list_page_enfant[id]'"));
            
        echo '<li>
                <span>
                    <input type="text" name="ordre[]" style="width:30px !important;" value="'.$list_page_enfant[ordre].'"><input type="hidden" name="id[]" style="width:15px !important;" value="'.$list_page_enfant[id].'">';
                    
                    //if($list_page_enfant[afficher]=='1' or $list_page_enfant[afficher]==''){echo'<img src="template/images/GreenDot.png" title="Afficher dans le site : OUI" /> ';}else{echo'<img src="template/images/RedDot.png" title="Afficher dans le site : NON" /> ';}
                        
                    if ($_SESSION[status] <= $selectparent[mod] or $_SESSION[status]=="1") {
                        echo '  <a class="load_droite" href="core/centres.php?module=pages&option=mod&pageid='.$list_page_enfant[id].'"><img width="20" alt="Modifier la page" title="Modifier la page" src="template/images/mod.png" border="0" /></a> ';
                    }
                    
                    if ($_SESSION[status] <= $selectparent[add]) {
                        echo '<a class="load_droite" href="core/centres.php?module=pages&option=add&pageid='.$list_page_enfant[id].'"><img width="20" alt="Ajouter une sous-page" title="Ajouter une sous-page" src="template/images/add.png" border="0" /></a> ';
                    }
                    
                    if ($_SESSION[status] <= $selectparent[del]) {
                        echo '<a class="confirmLink" href="core/centres.php?module=pages&option=del&pageid='.$list_page_enfant[id].'"><img width="20" alt="Supprimer la page" title="Supprimer la page" src="template/images/sup.png" border="0" /></a>';
                    }
                    
                    echo ' '.$list_page_enfant[titre].'
                </span> ';

                page_enfant($list_page_enfant[id], $level+1);   
                
            echo'</li>';
        }
        echo '</ul>';
    }
}
function page_treeview(){GlOBAL $_SESSION;
$select_page = mysql_query("SELECT * FROM pages WHERE parent='0' order by ordre asc") or die(mysql_error());  
if(count(mysql_num_rows($select_page))>0)
{
    echo '<div style="font-size:13px; margin:15px 0 15px 15px;">
    <form method="POST" id="ajaxform" class="load_form" action="core/centres.php?module=pages">
    <ul  id="page" class="treeview-red">';  
    while ($list_page = mysql_fetch_array($select_page))
    {
        echo '<li>
                <span>
                    <input type="text" name="ordre[]" style="width:30px !important;" value="'.$list_page[ordre].'"><input type="hidden" name="id[]" style="width:15px !important;" value="'.$list_page[id].'">';
                    
                        //if($list_page[afficher]=='1' or $list_page[afficher]==''){echo'<img src="template/images/GreenDot.png" title="Afficher dans le site : OUI" /> ';}else{echo'<img src="template/images/RedDot.png" title="Afficher dans le site : NON" /> ';}
                        
                        if ($_SESSION[status] <= $list_page[mod] or $_SESSION[status]=="1") {
                            echo '  <a class="load_droite" href="core/centres.php?module=pages&option=mod&pageid='.$list_page[id].'"><img width="20" alt="Modifier la page" title="Modifier la page" src="template/images/mod.png" border="0" /></a> ';
                        }
                        
                        if ($_SESSION[status] <= $list_page[add]) {
                            echo '<a class="load_droite" href="core/centres.php?module=pages&option=add&pageid='.$list_page[id].'"><img width="20" alt="Ajouter une sous-page" title="Ajouter une sous-page" src="template/images/add.png" border="0" /></a> ';
                        }
                        
                        if ($_SESSION[status] <= $list_page[del]) {
                            echo '<a class="confirmLink" href="core/centres.php?module=pages&option=del&pageid='.$list_page[id].'"><img width="20" alt="Supprimer la page" title="Supprimer la page" src="template/images/sup.png" border="0" /></a>';
                        }
                    
                    echo ' '.$list_page[titre].'
                </span> ';
                            
                page_enfant($list_page[id]);
                
        echo'</li>';
    }
    echo '</ul><br><input type="submit" value="Sauvegarder l\'ordre" name="saveordre"></form></div>';
}
}

 

It works great ... only problem is that it's very slow now that the client went crazy in adding his stuff ...

Is there any way i can make it go faster?

Edited by drisate
Link to comment
https://forums.phpfreaks.com/topic/282202-ifinite-loop-faster/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.