Skip to main content
Drymetal
Inspiring
July 23, 2012
Answered

Repeat Regions inside Repeat Regions

  • July 23, 2012
  • 1 reply
  • 7246 views

I'm not sure how to do this.  Dreamweaver says you can't put server behaviors inside server behaviors.   But it seems like a pretty standard thing someone might want to do.  For instance:

Let's say you wanted to create an online menu.  And say...you have two tables:

Table Items

  • item_id
  • item_name
  • item_description
  • item_price

Table Ingredients

  • ing_id
  • ing_name
  • item_id

So on your page, you want to show a repeat region of every menu item in the database.  Plus, inside each menu item, you want to have a repeat region of every ingredient that has the same item id.

Does that make sense?  So it may look like:

Fishy Lips
Wonderful Lips for all you Fishy Lip Lovers!  Get em today!

Ingredients

Fishy Lips

Fishy Seasonings

Fishy Herbs

Fishy Spices

Luckity Hoppity
Amazing Rabbit legs that bring good luck!

Ingredients

Bunny Legs

Bunny Spices

Cow Tongue

This topic has been closed for replies.
Correct answer bregent

No.  Set me on fire or something.  : )

Can you show me an example of what you mean?  I'm not use to working with loops so I don't understand that well.  Thanks!


Sorry, I'm not a php programmer, but I can explain the concept.

First of all, your idea of retrieving both recordsets and then displaying the matching data in the inner loop should work. But it seems to be you're fetching the wrong records.  If I understand this, you are getting a list of caregivers and then displaying the education for each. Correct? If so, then the caregiver is the outer loop, and education is the inner loop, yet your inner loop is advancing the caregiver RS: mysql_fetch_assoc($getCaregiver)

You might try just switching those.

However, it is more common to first retrieve the outer loop recordset. Then when you loop through that, you execute a new inner recordset for each iteration of the outer. Your SQL for the inner RS has a filter so that it only contains matching records.

1 reply

Drymetal
DrymetalAuthor
Inspiring
July 23, 2012

Here is what I've tried:

<form id="form1" name="form1" method="post" action="">

  <?php do { ?>

      <tr>

        <td><?php echo $row_getCaregiver['firstname']; ?></td>

        <td><?php echo $row_getCaregiver['lastname']; ?></td>

        <td><input name="cg_id" type="hidden" id="cg_id" value="<?php echo $row_getCaregiver['cg_id']; ?>" /></td>

        <td><?php do {

                    if($row_getEducation['cgid']= $row_getCaregiver['cg_id']){

                    echo $row_getEducation['ename'];

                    } ?></td>

      </tr>

      <?php } while ($row_getCaregiver = mysql_fetch_assoc($getCaregiver));

  } while ($row_getEducation = mysql_fetch_assoc($getEducation));

            ?>

</form>

This doesn't work though.  It only pulls one record from the Caregiver table and 3 duplicates of the first record in getEducation.   (There are 3 records in the Education table).

The result is showing this:

PersonA  Record1 Record1 Record1

I want it to show what is in the database though:

PersonA  Record1 Record2 Record3

PersonB

PersonC Record4

Participating Frequently
July 23, 2012

Your inner loop should execute a new SQL statement based on criteria from the outer statement.

So you loop through your menu items recordset. In each iteration, you execute the SQL for your ingredient recordset, using the item_id as a filter. Make sense?

Drymetal
DrymetalAuthor
Inspiring
July 23, 2012

No.  Set me on fire or something.  : )

Can you show me an example of what you mean?  I'm not use to working with loops so I don't understand that well.  Thanks!