i want to display some result using recursion first here is my table structure
contactid name reportsto
244797 ankit 9876
438 Mukti 244797
445 Moorthy 244797
446 P K Roy 244797
448 Suruchi 438
542 Lalit Kumar 438
543 Balkrishan 542
when i print_r($printres) then i receive only id whose reported to 244797 please check my code and evaluate my problem thanks.
Not a perfect example but i hope this will get you started. That will look something like this:
function recursive($reportsTo){
//make some logic that if contactid == reportsto does something (make table or layout)
recursive($contactId)
}
recursive(0)
I hope this query will help. You try this.
select contactid,name,'' level2,'' as level3, 0 ord,0 ord1,0 ord2 from tablename where reportsto=0 union select LW1.contactid,'' as name,LW.name level2,'' as level3,1 ord,LW.mid ord1,0 ord2 from tablename LW, tablename LW1 where LW.reportsto=LW1.contactid and LW.reportsto in(select contactid from tablename where reportsto=0) union select LW2.contactid,'' as name,'' as level2,LW.name as level3,1 ord,LW.reportsto ord1,1 ord2 from tablename LW,tablename tablename LW2 where LW.reportsto=LW1.contactid and LW1.reportsto=LW2.contactid and LW.reportsto in(select reportsto from iman_module where reportsto<>0) order by contactid,ord,ord1,ord2