drisate Posted September 16, 2013 Share Posted September 16, 2013 (edited) 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 September 16, 2013 by drisate Quote Link to comment https://forums.phpfreaks.com/topic/282202-ifinite-loop-faster/ Share on other sites More sharing options...
kicken Posted September 16, 2013 Share Posted September 16, 2013 Do only one query that pulls all the data, rather than a bunch of queries. Relevant reading: Building Tree Structures In Php Using References Quote Link to comment https://forums.phpfreaks.com/topic/282202-ifinite-loop-faster/#findComment-1449763 Share on other sites More sharing options...
drisate Posted September 16, 2013 Author Share Posted September 16, 2013 Thx, looks like a better solution indeed! Quote Link to comment https://forums.phpfreaks.com/topic/282202-ifinite-loop-faster/#findComment-1449766 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.