Jump to content
Server Maintenance This Week. ×

Problem sorting value list in dynamic drop down menu


This topic is 4007 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies

Ok, I'm pretty new to PHP, so please be gentle with me :-)

 

The page that I'm working on shows events listings by date. When the user initially comes to the page, all events that are in the future show on a results table. Said another way, all past events are already filtered out. By default, the events are shown in date order. 

 

The page has drop down menus to filter the results further. The drop down menus are dynamic from the Filemaker database, and they only show data from events in the future (not the past). The filter at issue here is the one for the Type of Event (conference, webinar, etc).

 

On Filemaker, the data is in just one table - no related table, no portals, etc. I'm working on the KISS principle. 

 

The dynamic drop down menus work just fine in terms of searching and filtering the data, but I just have one problem with them -> they do not display the options in alphabetical order. I would think that some sort( ) somewhere would 'sort' things out (bad pun, I know, but I've been at this for a while), but I can't make it work. 

 

I cannot find any logic as to how they are currently sorted. I unsorted the records and changed the entries to numbers, and they now come up in this order: 8, 2, 3, 18, 13, 17, 5, 14, 21. And that order does not correlate with the order for any other field. It's about as logical as the winning lottery numbers. 

 

I'm using Filemaker 12. And the code that I'm using below. 

 

My Grandfather use to say that most solutions are 'awfully simple' or 'simply awful'. I'm hoping for the former.

 

Many many thanks.

 

Snowball a/k/a Cin 

 

 

 
<form name="form1" id="form1" action="home_results_new.php" method="post">
  <p id="form1">
  <br />
  <b>Type:</b>
  <select name="type" style="width:200px;">
  <option value="*">Select a Type</option>
 
<?php
        //foreach ($valueListb as $myvalueb)
      {
       ?>
 
     <?php
         $displayedType = array();
         sort($LineItems2_result->getRecords());
         foreach($LineItems2_result->getRecords() as $LineItems2_row) {
         $my_type = $LineItems2_row->getField('type');
         if (in_array($my_type, $displayedType)) {
                    // already seen it
            continue;
        }
        ?>
 
    <option value="<?php echo $my_type; ?>"><?php  echo $my_type; ?></option> 
   
    <?php //}
          ?>
     
     <?php
        $displayedType[] = $my_type;
         }
        ?>
 
  </select>
  
 
  
  
  
  
  

 

Link to comment
Share on other sites

I'll bet they are displaying in creation order.

 

Two solutions:

- Delete and recreate in desired order

- Query the table directly and build your web value list that way - you can apply a sort on the query

Link to comment
Share on other sites

  • Newbies

Hi, 
Thanks for responding. I had thought that it would be creation order, so I unsorted and put numbers in.... Just now I added a new entry (22) and it showed up 4th from the bottom.... so I think that rules that out. 

 

In terms of Plan B - can you walk me thru that a bit? In terms of querying the table, I can see that it goes thru a loop now. Can you point me in the direction of doing it in two steps - query and then loop? 

 

Thanks, 

Snowball a/k/a Cin

Link to comment
Share on other sites

  • Newbies

Ok, looking at the code that comes earlier on the page, there is this: 

 

<?php
$valueListb = $layoutObject->getValueList('type');
?>
 
Using sort ( ) and print_r ( )  I see that that command gets the array from the database. However, valueListb does not seem to be used in the code posted above. Is there somewhere that I could substitute $valueListb or use that in the code in the original post to make it work? 
 
 
AND on further investigation, there is some relevant code at the top of the page (below). This creates the variable and is used to filter out the results from dates that have passed. 
 
<?PHP
$LineItems2_find = $conn->newFindCommand('Table_1');
$LineItems2_findCriterions = array('name'=>'*','date_entry'=>'>'.$today,); 
foreach($LineItems2_findCriterions as $key=>$value) {
$LineItems2_find->AddFindCriterion($key,$value);
}
 
fmsSetPage($LineItems2_find,'LineItems2',1000);
 
$LineItems2_result = $LineItems2_find->execute(); 
 
fmsSetLastPage($LineItems2_result,'LineItems2',1000);
 
if(FileMaker::isError($LineItems2_result)) {
 
//echo "no cities available for this country";
 
//header("Location: login_error_display.php?email=$email_address"); 
 
}else{
 
$LineItems2_row = current($LineItems2_result->getRecords());
 
//$city = $LineItems_row->getField('location_city');
}
?>
 
 
So then when I do print_r($LineItems2_row) I get basically all the fields from the database:
 
FileMaker_Record Object ( [_impl] => FileMaker_Record_Implementation Object ( [_fields] => Array ( [space] => Array ( [0] => ) [name] => Array ( [0] => 2013 IEEE Aerospace Conference ) [name_with_html] => Array ( [0] => 2013 IEEE Aerospace Conference ) [date_date] => Array ( [0] => May 29, 2013 ) [date_entry] => Array ( [0] => 05/29/2013 ) [date_month_year] => Array ( [0] => May 2013 ) [date_sort_entry] => Array ( [0] => 735017 ) [date_for_form_layout] => Array ( [0] => May 29, 2013 ) [location] => Array ( [0] => San Jose, CA, USA ) [location_with_html] => Array ( [0] => San Jose, CA, USA ) [location_city] => Array ( [0] => San Jose ) [location_state] => Array ( [0] => CA ) [location_country] => Array ( [0] => USA ) [type] => Array ( [0] => 3 ) [type_with_html] => Array ( [0] => webinar ) [provider] => Array ( [0] => 120 ) [provider_with_html] => Array ( [0] => 2 ) [id] => Array ( [0] => 2 ) 

 

(this stuff if repeated for each entry, but I thought I'd not post it all).

 
If I remove the sort from this line: 
         sort($LineItems2_result->getRecords());
 

then it does change the order of the records.... but neither orders are logical. So it has dawned on me that with all of the information in the variable, when the command 'sort' is used, then I'm not clear what it's using to perform the sort... what the sort is based on. 

 

So, is there a way to make it perform the sort based on 'type', 

or is there a way to filter out the information from the other fields and have just the 'type' information, 

or am I talking crazy talk? 

 

 

Thanks, 
Snowball a/k/a Cin
Link to comment
Share on other sites

This topic is 4007 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.