Welcome Guest, Not a member yet? Register   Sign In
query problem
#1

[eluser]Bigil Michael[/eluser]
I would like to create a menu like this from a single table
Code:
two wheeler
four wheeler
     jeep
     cars
             Audi
             BMW
             Benz

Code:
I have created  table with name menus, like this

id    parent     menu_name
1        0            two wheeler
2        0            four wheeler
3        1            cars
4        1            jeep
5        3            Audi
6        3            BMW
7        3            Benz

i wrote the query like this
Code:
SELECT p.menu_name as menu,d.menu_name as sub_menu,f.menu_name as sub_sub_menu FROM menus AS p join menus d on d.parent = p.id join menus f on f.parent = d.id

and tried to print the result in a normal way
Code:
<?php
foreach($list_menu as $row) {
   echo $row->menu.'<br/ >';
     echo '&nbsp;&nbsp;'.$row->sub_menu.'<br/ >';
     echo '&nbsp;&nbsp;&nbsp;&nbsp;'.$row->sub_sub_menu.'<br/ >';
} ?&gt;
got the result like this
Code:
four weeler
  cars
    Audi
four weeler
  cars
    BMW
four weeler
  cars
    benz
here two wheeler, jeep etc are missing and not in proper format.

can anyone help me to solve this issue....


Messages In This Thread
query problem - by El Forum - 02-20-2014, 02:44 AM
query problem - by El Forum - 02-20-2014, 07:14 AM
query problem - by El Forum - 02-20-2014, 07:57 AM
query problem - by El Forum - 02-21-2014, 12:31 PM
query problem - by El Forum - 02-21-2014, 10:17 PM
query problem - by El Forum - 02-25-2014, 11:40 PM
query problem - by El Forum - 02-26-2014, 10:15 PM
query problem - by El Forum - 02-27-2014, 05:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB