0

This is the way I need to display my data:

Electronics        main heading
      Mobile        category
         Galaxy s   sub category

I'm using three tables: mainheading, category and subcategory. All have a foreign key to each.

I want to know which would be efficient method to display this kind of data.I was reading about these methods: Adjacency list, Path enumeration, Nested sets, Closure table.

Can you also point out a good example for implementing this?

After join,this is how my table looks like

1. Electronics mobile Galaxy s

   $x = "";
   $z = "";
    while()
     { 
   if($x != $mainheading)
     {
            $y =    $row['mainheading'];
       $x = $y;
      }
    if($y != $category)
       {
              $s =    $row['category'];
             $z = $s;

       }
   }

DB Structure

Main Heading sno primary key mainheading

Category

sno primartkey msno foriegn key category

Sub Item

sno primary key csno foriegn key subitem

I used join on three tables to form above

Electronics mobile Galaxy s

HTML

        <div> Main Heading <div> </div>
        </div>
        <div><second opens>
        <div><third close>
       <h3> Category</h3>

        <div>
        <p>Sub item</p> </div>
        </div><third close?
       </div><second close>
ram
  • 1,111
  • 6
  • 15
  • 24
  • Please be more specific with your question and provide some more information. – wasim kazi Aug 30 '12 at 06:01
  • @wasim kazi:Can you tell me what was not clear in my question so that i can update my question. – ram Aug 30 '12 at 06:02
  • From where you want to display this data and if you making proper join so that is easy to maintain this kind of tree. and in this if you used **Adjacency list** is a good idea. [Check here](http://stackoverflow.com/questions/4242276/recursive-php-function-for-adjacency-list-display) – wasim kazi Aug 30 '12 at 06:06
  • @wasim kazi:From database,i used joins and got every thing in one table but while i loop them using php,i get problem,can you tell me ,what logic should i use in PHP. – ram Aug 30 '12 at 06:07
  • Please add your logic into that so we can understand it and try to solve your problem. – wasim kazi Aug 30 '12 at 06:10
  • @wasim kazi:Updated my question with logic.If i use with out html,it is displaying correctly ,my logic get messed up,when i use HTML. – ram Aug 30 '12 at 06:15
  • @user1605962 your update is not good enough; provide your current db structure, real code and what problems you're facing. – Ja͢ck Aug 30 '12 at 06:30
  • @user1605962 You just need to use right html code. means goggling to use html with php and make some proper loop. may be while loop will work with your situation. – wasim kazi Aug 30 '12 at 06:34
  • @wasim kazi:Updated my db structure too.You mean not to use if loop,only using while loop will do.Can you give me some eg. – ram Aug 30 '12 at 06:37
  • @Jack:Updated my db structure. – ram Aug 30 '12 at 06:37
  • @user1605962 please add your html code and detail it what error you face. you say in logic you got proper output so please add it with html and then show what error you face. – wasim kazi Aug 30 '12 at 06:40
  • @wasim kazi:Is my php logic correct ?i've added my html. first category is coming correctly under main heading from next ,it is outputting to outside div.I may be wrong with my php logic. – ram Aug 30 '12 at 06:45
  • Is your question regarding the UI display or the backend sql processing? Please remove the part that is not required. See [ask] – mtk Aug 30 '12 at 06:58

1 Answers1

1

Try this

while($row)
{
 if($x != $mainheading)
  {
    $y =    $row['mainheading'];
    $x = $y;
   echo "<div>"; echo $x; echo "<div>";
  }
   if($y != $category)
   {
      $s = $row['category'];
      $z = $s;
     echo "<div>"; echo $z; echo "<div>"; 
   }

  and so on...... 
}  
wasim kazi
  • 378
  • 4
  • 13
  • :sub item div should not repeat but it is repeating when i've two data for it.Only h3 tag should repeat. – ram Aug 30 '12 at 10:25
  • use foreach loop insted of while and make foreach loop for h3 tag. That will solve your problem. – wasim kazi Aug 31 '12 at 04:57