Jump to content

[SOLVED] Need Help on Looping


andz

Recommended Posts

Good day guys

 

Could you help me out sort this problem.

 

 

The table below will illustrate what i need to achieve.

 

 

Parent 1

  Sub Parent 1.1

    Child 1000

    Child 2000

Parent 2

  Sub Parent 2.2

    Child 3000

    Child 4000

Parent 3

  Sub Parent 3.3

 

 

I want to create a loop that will look like that on the result but i'm not good enough on it.

 

Ciould you help me guys?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/146961-solved-need-help-on-looping/
Share on other sites

Parent 1

  Sub Parent 1.1

    Child 1000

    Child 2000

Parent 2

  Sub Parent 2.2

    Child 3000

    Child 4000

Parent 3

  Sub Parent 3.3

 

 

 

 

if($parent1) {
  if($sub_parent1) {
    echo "child1000";
    echo "child2000";
   }
}elseif($parent2) {
  if($sub_parent2) {
    echo "child3000";
    echo "child4000";
   }elseif($parent3) {
  if($sub_parent3) {
    echo "child5000";
   }
}

How abbout something like this:

$command1 = mysql_query("Select * FROM $table ") or die(mysql_error());
while ($data1 = mysql_fetch_array($command1)){

echo $data1[parent];

$command2 = mysql_query("Select * FROM $table where parent='$data1[parent]'") or die(mysql_error());
while ($data2 = mysql_fetch_array($command2)){

echo "   ".$data2[sub];

$command3 = mysql_query("Select * FROM $table where sub='$data2[sub]'") or die(mysql_error());
while ($data3 = mysql_fetch_array($command3)){

echo "      ".$data2[child];

}

}
}

 

Whats up allworknoplay :-)

Nice to see your stickying arround

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.