我正在使用我的数据库中的数据填充选择框。(SQL 服务器 2008)。
这是我的功能:
function sample_items($product_types = array('METER KIT', 'TEST STRIP', 'LANCET', 'CONTROL SOLUTION', 'LANCING DEVICE', 'BATTERY', 'MISC'))
{
$a = array();
$i = 0;
$def = $product_types;
foreach($product_types as $k)
{
$qty = sql::one_row("select min_, max_, interval from event.dbo.product_type where product_type = " . hexstr($k));
$label = str_replace('CONTROL SOLUTION', 'C/S', $k);
$label = str_replace('LANCING DEVICE', 'L/D', $label);
$a[] = input_check("items[ok][$i]")->label($label);
if ($k == 'TEST STRIP')
{
$a[] = input_select("items[ptcode][$i]", sql::two_column_array("select rtrim(a.CODE_), case when B.id IS NULL THEN rtrim(a.DESCRIPTION_) else 'BACKORDER:'+RTRIM(a.DESCRIPTION_) end
from PACWARE.ADS.PTDME a left outer join event.dbo.backorder b on a.CODE_=b.ptcode where a.MEDICAREID = 'SAMP' and a.DESCRIPTION_ like '%STRIP%'"), 1)->label('')->same_line()->set_class('wide2');
}
else if ($k == 'LANCET')
{
$a[] = input_select("items[ptcode][$i]", sql::two_column_array("select rtrim(a.CODE_), case when B.id IS NULL THEN rtrim(a.DESCRIPTION_) else 'BACKORDER:'+RTRIM(a.DESCRIPTION_) end
from PACWARE.ADS.PTDME a left outer join event.dbo.backorder b on a.CODE_=b.ptcode where a.MEDICAREID = 'SAMP' and a.DESCRIPTION_ like '%LANCET%'"), 1)->label('')->same_line()->set_class('wide2');
}
else if ($k == 'MISC')
{
$a[] = input_select("items[ptcode][$i]", \Ptdme::items_by_product_type(array('SAMPLE PRODUCT','MISCELLANEOUS SUPPLIES')), 1)->label('')->same_line()->set_class('wide2');
}
else { $a[] = input_select("items[ptcode][$i]", \Ptdme::items_by_product_type($k), 1)->label('')->same_line()->set_class('wide2'); }
if (!empty($qty)) $a[] = input_select("items[qty][$i]", range($qty['min_'], $qty['max_'], $qty['interval']))->label();
else $a[] = input_select("items[qty][$i]", range(0, 100))->label();
$i++;
}
return input_group('Items', $a)->whole();
}
它位于一个输入组中,该组只是一个带有一些 css 的小表格。
保存后,我创建了另一个函数来为此示例页面构建“事件表单”。
这是那个功能:
function new_pt_ss()
{
if ($this->create_npc_SS)
{
$task_id = '13';
if (sql::value("select 1 from event.dbo.event where task_id =" . hexstr($task_id). " and status = 1 and patient_id = " . $this->patient->hex))
return Message::add('New Patient Sample CC already exists. Event not created.', 'warn');
$defs = array('METER KIT', 'TEST STRIP', 'LANCET', 'CONTROL SOLUTION', 'LANCING DEVICE', 'BATTERY', 'MISC');
$task_params = array();
$oks = $this->get_oks();
$oks_hex = array();
foreach ($oks as $k=>$v) $oks_hex[] = hexstr($k);
$qtys = zip($this->items['ptcode'], $this->items['qty']);
foreach ($defs as $x)
{
$me = 0;
foreach ($pt_types as $num=>$row)
{
if ($row['ev_product_type'] == $x)
{
$task_params["{$row['ev_product_type']}"] = $row['ptcode'];
$task_params["{$row['ev_product_type']}_qty"] = $qtys[$row['ptcode']];
if ($x == 'control_solution') $task_params['cs_bill'] = '1';
else if ($x == 'lancing_device') $task_params['lancing_bill'] = '1';
unset($pt_types[$num]);
$me = 1;//continue 2; // preserves sorting instead of continue
}
}
}
$task_params = array_merge($task_params, array('ship_date'=>$this->ship_date
,'urgent'=>$this->urgent
,'valid_po'=>$this->valid_po
,'shipping_method'=>$this->shipping_method
,'reason'=>$this->reason
,'on_insulin'=>$this->on_insulin
,'patient_on_insulin'=>$this->patient_on_insulin
));
Message::check($this->patient->event()->create($task_id, $task_params), "Create Sample CC event.");
return "NEW PT Sample CC EVENT TO BILLING FOR DOS $this->ship_date.";
}
}
提交后,如果尚未为示例 ss 创建事件,否则$task_id = '13';
将创建事件并填充这些字段:
,'urgent'=>$this->urgent
,'valid_po'=>$this->valid_po
,'shipping_method'=>$this->shipping_method
,'reason'=>$this->reason
,'on_insulin'=>$this->on_insulin
,'patient_on_insulin'=>$this->patient_on_insulin
问题是我不确定如何在我的每个循环中填充所有复选框和选择框。
这些是需要在事件表单上填充的字段名称:
<tr><td>Meter</td><td><?php sbox('part1',ptdme('E0607'),1, "' onChange=\" reason_swap(this); \" '"); ?></td><input type='hidden' value='1' name='part1_qty'/></tr>
<tr name='inact1' title='56151124' style='display:none;'><td></td>
<td>Send True2Go Meter? <input type='checkbox' name='part8' value='21292002590'/></td><input type='hidden' value='1' name='part8_qty'/></tr>
<tr><td>Strips</td><td><?php sbox('part2', $samp_strips,1,'wide2'); ?></td><td><?php sbox('part2_qty', range(1,10)); ?></td></tr>
<tr><td>Lancets</td><td><?php sbox('part3', $samp_lancets,1,'wide2'); ?></td><td><?php sbox('part3_qty', range(1,10)); ?></td></tr>
<tr><td>Control</td><td><?php sbox('part4', ptdme('A4256'),1,'wide2'); ?></td><input type='hidden' value='1' name='part4_qty'/></tr>
<tr><td>L/D</td><td><?php sbox('part5', ptdme('A4258'),1,'wide2'); ?></td><input type='hidden' value='1' name='part5_qty'/></tr>
<tr><td>Battery</td><td><?php sbox('part6', ptdme('A4235'),1,'wide2'); ?></td><td><?php sbox('part6_qty', range(1,2)); ?></td></tr>
<tr><td>Misc</td><td><?php sbox('part7', ptdme2(array('SAMP','MISC')),1,'wide2'); ?></td><td><?php sbox('part7_qty', range(1,10)); ?></td></tr>
</table>
</fieldset>
我希望这是有道理的,如果需要,我很乐意提供更多信息。