Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to control order of files being displayed in dynamic select box

Posted on 2012-04-05
4
Medium Priority
?
308 Views
Last Modified: 2012-04-06
I haven't touched PHP in about 11 years so be kind to me! I need to update code that builds a dynamic select on a page. It just reads in the files. How can I control the order of the files displayed? I want a specific file to be first.
/////////////////////////////////////////////////////////////////////
function load($htmlFrm, $cancelFormSubmission){
            global $OMNITURE_REPORTS_DIR;
            
            // load the drop down data
            $type = $this->dataRow['type']->getValue();
            $typeFilter = "val not like 'locale%'"; // by default do not show locale types.
            if (preg_match('/locale/', $type)){
                  $typeFilter = "val like 'locale%'";
            }
            $this->typeList = new CSimpleDataSet($this->db, new CQuery(new CString("SELECT caption, val FROM lists WHERE groupName='opsr2.omniture.type' AND $typeFilter ORDER BY priority ASC")));
            $this->typeList->loadData();

            // get the report template file list;
            if (self::$reportList === null){
                  self::$reportList = array();
                  foreach (scandir($OMNITURE_REPORTS_DIR) as $file){
                        // only show files in the reports menu, not directories.
                        if (is_file("$OMNITURE_REPORTS_DIR/$file")){
                              self::$reportList[] = new CString($file);
                        }
                  }
            }
/////////////////////////////////////////////////////////////////////////////////////////
// generate a report list pulldown menu:
                  if (count(self::$reportList)){
                        $reportSel = new CSelect($this->parentReport->getHtmlFrm(), new CString("reportSelector"), new CString(''));
                        $reportSel->setClassName('reportSelector');
                        foreach (self::$reportList as $file){
                              $reportSel->addOption($file,$file);
                        }
                        $tpl->assign('html_reportSelector',$reportSel->getHtml());
                  } // end: if
0
Comment
Question by:894359
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 37814584
What are these classes from (maybe part of a larger framework?)  How do you know which file you want to display first?  File name?  Oldest?  Newest?  There are probably some ways to make an array of objects that would allow many different ways to sort the list of files or pick out the one you want first.
0
 

Author Comment

by:894359
ID: 37814588
I want to display a specific file name first.
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 total points
ID: 37814600
I believe that scandir() returns an array of file names.  There is this line in the code:  foreach (scandir($OMNITURE_REPORTS_DIR) as $file){  That would suggest to me that you might look at the file names inside the iterator loop created by foreach() and select the desired file.  Add it to an output array at position zero.  Remove it from the scandir() results.  Then iterate over the scandir() results again, adding the rest of the file names to the output array.
0
 
LVL 13

Accepted Solution

by:
Hugh McCurdy earned 1000 total points
ID: 37814655
You could also use the dir() class in php.

http://php.net/manual/en/function.dir.php

The page also has an example.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question