Last active
December 22, 2015 08:48
-
-
Save uded/6447380 to your computer and use it in GitHub Desktop.
The last iteration, `while ($row = $result->FetchRow()) {` does include an option to use associative arrays to manage a multi select list with both display and value or a non-associative array for just values which will be used to as text display in the select widget.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
public static function getVariableOptions($params, &$report) { | |
$report->conn->SetFetchMode(ADODB_FETCH_NUM); | |
$query = 'SELECT DISTINCT '.$params['column'].' FROM '.$params['table']; | |
if(isset($params['where'])) { | |
$query .= ' WHERE '.$params['where']; | |
} | |
$macros = $report->macros; | |
foreach($macros as $key=>$value) { | |
if(is_array($value)) { | |
foreach($value as $key2=>$value2) { | |
$value[$key2] = mysql_real_escape_string(trim($value2)); | |
} | |
$macros[$key] = $value; | |
} | |
else { | |
$macros[$key] = mysql_real_escape_string($value); | |
} | |
if($value === 'ALL') $macros[$key.'_all'] = true; | |
} | |
//add the config and environment settings as macros | |
$macros['config'] = PhpReports::$config; | |
$macros['environment'] = PhpReports::$config['environments'][$report->options['Environment']]; | |
$result = $report->conn->Execute(PhpReports::renderString($query, $macros)); | |
if (!$result) { | |
throw new Exception("Unable to get variable options: ".$report->conn->ErrorMsg()); | |
} | |
$options = array(); | |
if(isset($params['all']) && $params['all']) { | |
$options[] = 'ALL'; | |
} | |
while ($row = $result->FetchRow()) { | |
if ($result->FieldCount() > 1) { | |
$options[] = array('display'=>$row[0], 'value'=>$row[1]); | |
} else { | |
$options[] = $row[0]; | |
} | |
} | |
return $options; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
while ($row = $result->FetchRow()) { | |
if ($result->FieldCount() > 1) { | |
$options[] = array('display'=>$row[0], 'value'=>$row[1]); | |
} else { | |
$options[] = $row[0]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment