|
Posted by MS on 10/11/31 11:56
> I don't know if this has any application to what you're doing but this
> snippet may be of interest.
>
> Trying to build a dynamic label like this fails:
> $label = 'p' .
> $srcnumber .
> '_label';
>
> But do this:
>
> $label=${'p' . $srcnumber . '_label'};
>
> Get this:
>
> $label = $p0_label;
>
Thanks for your help....
I have now changed my coding, which now uses static variable names.
The code is to produce $sel_... variables that contain the code for
selection boxes & $ck_... variable to contain the code for Checkbox lists.
Code in Static Form
// Create Selection Lists V2
function GetData($type){
global $table_prefix;
$sql = dbquery("SELECT list_id, list_name FROM ".$table_prefix."lists
WHERE list_type = '".$type."'
ORDER BY list_order");
$i=0;
while($temp = dbarray($sql)){
$ret[$i]['id'] = $temp['list_id'];
$ret[$i]['name'] = $temp['list_name'];
$i++;
}
return $ret;
}
$sel_enqtype = GetSelection(GetData("enqtype"),$bk_enqtype);
$sel_acctype = GetSelection(GetData("acctype"),$bk_acctype);
$sel_pmc = GetSelection(GetData("pmc"),$bk_pmc);
$sel_howfind = GetSelection(GetData("howfind"),$bk_howfind);
$ck_rooms = GetCheckbox("rooms",GetData("rooms"),$bk_rooms);
// Create a selection list from an array id, name
function GetSelection($listarray,$selected=""){
$res = "";
for ($i=0;$i <= count($listarray);$i++) {
$sel = ($selected == $listarray[$i]['id']? " selected" : "");
$res .= "<option
value='".$listarray[$i]['id']."'$sel>".$listarray[$i]['name']."</option>\n";
}
return $res;
}
// Create a checkbox list from an array id, name
function GetCheckbox($name,$listarray,$selected=""){
$res = "";
$selsplit = explode(',',$selected);
for ($i=0;$i < count($listarray);$i++) {
$sel = (in_array($listarray[$i]['id'],$selsplit)? " checked" : "");
$res .= "<input type='checkbox' name='".$name."[".$i."]'
value='".$listarray[$i]['id']."'$sel>".$listarray[$i]['name']."<br>\n";
}
return $res;
}
.............................................................................
......................................
The variables above are hard coded now... but my plan was to use Variable
Variables like in the following Code
$lists = array("enqtype","acctype","pmc","howfind","rooms");
foreach($lists as $listval){
$$listval = dbquery("SELECT list_id, list_name FROM
".$table_prefix."lists
WHERE list_type = '".$listval."'
ORDER BY list_order");
$i=0;
while($temp = dbarray($$listval)){
$sel_{$listval}[$i]['id'] = $temp['list_id'];
$sel_{$listval}[$i]['name'] = $temp['list_name'];
$i++;
}
}
// Which would give me variable... $sel_{enqtype} $sel_{acctype} etc...
// I did want variables $sel_enqtype without the {} braces.
Navigation:
[Reply to this message]
|