MJ
asked on
How to control order of files being displayed in dynamic select box
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']->ge tValue();
$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_REPORT S_DIR/$fil e")){
self::$reportList[] = new CString($file);
}
}
}
////////////////////////// ////////// ////////// ////////// ////////// ////////// ////////// ///
// generate a report list pulldown menu:
if (count(self::$reportList)) {
$reportSel = new CSelect($this->parentRepor t->getHtml Frm(), new CString("reportSelector"), new CString(''));
$reportSel->setClassName(' reportSele ctor');
foreach (self::$reportList as $file){
$reportSel->addOption($fil e,$file);
}
$tpl->assign('html_reportS elector',$ reportSel- >getHtml() );
} // end: if
//////////////////////////
function load($htmlFrm, $cancelFormSubmission){
global $OMNITURE_REPORTS_DIR;
// load the drop down data
$type = $this->dataRow['type']->ge
$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.
$this->typeList->loadData(
// get the report template file list;
if (self::$reportList === null){
self::$reportList = array();
foreach (scandir($OMNITURE_REPORTS
// only show files in the reports menu, not directories.
if (is_file("$OMNITURE_REPORT
self::$reportList[] = new CString($file);
}
}
}
//////////////////////////
// generate a report list pulldown menu:
if (count(self::$reportList))
$reportSel = new CSelect($this->parentRepor
$reportSel->setClassName('
foreach (self::$reportList as $file){
$reportSel->addOption($fil
}
$tpl->assign('html_reportS
} // end: if
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.
ASKER
I want to display a specific file name first.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.