Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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