Skip navigation
Currently Being Moderated

Repeat Regions inside Repeat Regions

Jul 23, 2012 9:36 AM

Tags: #php #dreamweaver #regions #nested #repeat

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

 
Replies
  • Currently Being Moderated
    Jul 23, 2012 12:00 PM   in reply to Drymetal

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 23, 2012 12:20 PM   in reply to Drymetal

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 23, 2012 1:26 PM   in reply to Drymetal

    That error means you are trying to reference an index that is out of bounds. Looks like you are not resetting the inner recorset to the first record after looping through it. I'm not sure what the function is for that, but it should be easy to find.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points