• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Repeat region with limits

Community Expert ,
Aug 17, 2012 Aug 17, 2012

Copy link to clipboard

Copied

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.

TOPICS
Server side applications

Views

731

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 18, 2012 Aug 18, 2012

Copy link to clipboard

Copied

LATEST

It looks like I've stumped the community. Anyone have any ideas about where to look?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines