Skip navigation
Currently Being Moderated

Repeat region with limits

Aug 17, 2012 12:25 PM

Tags: #if/else #region #repeat

I'm building a list for a menu system using php a database table called content and the standard repeat region behavior. I've done this many times before. My "contentRS" table looks like this:

 

 

idlinkclass
1page_01red
2page_02green
3page_03red
4page_04blue
5page_05green
6page_06red

 

I want to generate a list but only show that list when the class = red. Hiding the list when the class does not equal red is easy. Limiting the list to only records with a class = red is the problem.

 

I've set up the following code:

<?php do { ?>
              <?php if ($row_contentRS['class'] == "red") {
          echo "<li>" .$row_contentRS['class'] . "</li>";
                    } ?>
              <?php } while ($row_contentRS = mysql_fetch_assoc($row_contentRS)); ?>

 

The first part works just fine. The repeat region, however, repeats all of the links so I end up with this: (as expected)

  • page_01
  • page_02
  • page_03
  • page_04
  • page_05
  • page_06

What I want is this:

  • page_01
  • page_03
  • page_06

 

I can modify the contentRS by editing the query so the RS only reveals the records with a class of "red" by modifying the record set with the following statement:

 

SELECT *
FROM content
WHERE class = 'red'

 

This solves my problem, except that I have 90 different class variables now and I will end up with a bunch more. I don't want to have to create a different record set for each. I already know how to reuse the repeat region. What I'd like to do is figure a way embed the query where statement into the repeat region command so only the red class would show up in the list, then reuse the statement with each of the different variables to create a drop down menu with each class listed in the menu bar.

 

If I can figure this out setting up all 90 classes will be simple copy and paste then typing in a new class value instead of creating 90+ record sets for my menu.

 

If someone has any ideas I'd appreciate it very much. I may be barking up the wrong tree.

 
Replies

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