Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Filter recordset

  1. #1
    Join Date
    Jan 2009
    Posts
    17
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Filter recordset

    I have a table with 2 fields. I want to display a recordset on a page that displays the results of field 2. That is easy, I have done that, however I want to change the result to display the value from field 2 only if field 1 contains a certain value.

    My recordset code looks like this:

    <?php echo $row_Recordset1['field2']; ?></p>

    This is probably really easy but I am having some trouble.

    Thanks,
    Dave

  2. #2
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Try something like this:
    PHP Code:
    <?php

    if($row_Recordset1['field1'] == '**ENTER_CERTAIN_VALUE**') {

    echo 
    $row_Recordset1['field2']."</p>";

    }

    ?>
    HTH
    - Josh

  3. #3
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    The other approach to this would be to do it in your Select statement.

    PHP Code:
    $value="selection criteria";
    $row mysql_query("SELECT field2 FROM mytable WHERE field1=$value"); 
    This way you only get the records that match the required selection criteria

  4. #4
    Join Date
    Jan 2009
    Posts
    17
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Thanks, that worked good. What I need to do now is display a different set of values from the same table. One line shows the results of field 2 when field 1 is equal to one value. The next line will show the results of field 2 when field 1 is equal to a different value. My thought is that I would do this:

    Code:
    <?php
    
    if($row_Recordset1['department'] == 'Childrens Church') {
    
    echo $row_Recordset1['names']."</p>";
    
    }
    
    ?>
    
     <?php
    
    if($row_Recordset1['department'] == 'Welcome Ministry') {
    
    echo $row_Recordset1['names']."</p>";
    
    }
    
    ?>
    This is not working for some reason?

  5. #5
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Try this

    PHP Code:
    <?php

    if($row_Recordset1['department'] == 'Childrens Church') {

    echo 
    $row_Recordset1['names']."</p>";

    }else if(
    $row_Recordset1['department'] == 'Welcome Ministry') {

    echo 
    $row_Recordset1['names']."</p>";

    }

    ?>

  6. #6
    Join Date
    Jan 2009
    Posts
    17
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    It is still only showing the one set of records "Childrens Church".

  7. #7
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    This should be working ...

    PHP Code:
    <?php

    if($row_Recordset1['department'] == 'Childrens Church') {

    echo 
    $row_Recordset2['names']."</p>";

    }

    if(
    $row_Recordset2['department'] == 'Welcome Ministry') {

    echo 
    $row_Recordset1['names']."</p>";

    }

    ?>
    is it not?
    - Josh

  8. #8
    Join Date
    Jan 2009
    Posts
    17
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    I noticed in th reply you RecordSet1 & RecordSet2. How should I create those record sets?

  9. #9
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    I meant this:

    PHP Code:
    <?php

    if($row_Recordset1['department'] == 'Childrens Church') {

    echo 
    $row_Recordset1['names']."</p>";

    }

    if(
    $row_Recordset1['department'] == 'Welcome Ministry') {

    echo 
    $row_Recordset1['names2']."</p>";

    }

    ?>
    ... changing names2 to whatever field you want to have displayed.
    - Josh

  10. #10
    Join Date
    Jan 2009
    Posts
    17
    Thanks
    0
    Thanked 1 Time in 1 Post

    Smile

    Yes, that is working now, one thing that I noticed I had not done is, I didn't have the dynamic text inside a repeat region, so it was just displaying the first result.

    Thanks so much for your help,
    Dave

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •