请有人建议如何在下拉列表中显示数据吗? 选项属性中将使用哪些代码?
我的控制器
public function tableReports()
{
$data['tables']=$this->DbReports->selectTable('snehal_pharma');
$this->load->view('reports/rpt.php');
}
型号代码
function selectTable($db)
{
$query=$this->db->list_tables();
print_r($query);
return $query;
}
查看
<div class="span12">
Table List :
<select name="tbl" style="width: 150px;">
<?php foreach($tables->result() as $tbl){ ?>
<option><?php echo $tbl;?></option>
<?php } ?>
</select>
</div>
输出
数组([0] =&gt; account_groups [1] =&gt; account_undergroup [2] =&gt; batch_master [3] =&gt; batch_packing [4] =&gt; batch_stock [5] =&gt; company_master [6] =&gt; cost_sheet [7] =&gt; cost_sheet_details [8] =&gt; customer [9] =&gt; departments [10] =&gt; disp_material [11] =&gt; dm_gatepass [12] =&gt; equipment_master [13] = &gt; es_finance_master [14] =&gt; es_ledger [15] =&gt; es_voucher [16] =&gt; es_voucherentry [17] =&gt; exipient [18] =&gt; mail_date [19] =&gt; pm_issue [20] =&gt ; purchase [21] =&gt; purchase_details [22] =&gt; purchase_indent [23] =&gt; purchase_items [24] =&gt; purchase_master [25] =&gt; purchase_order [26] =&gt; sales [27] =&gt; sales_details [28] =&gt; sales_items [29] =&gt; sales_master [30] =&gt; sop_master [31] =&gt; stock_register [32] =&gt; stockcategory [33] =&gt; stockmaster [34] =&gt; supplier_master [35] =&gt; supply_order [36] =&gt; taxcategories [37] =&gt; tbl_state [38] =&gt; tbluser [39] =&gt; unit_pack [40] =&gt; unitsofmeasure [41] =&gt; v iew_salesledger [42] =&gt; viewbatchstock [43] =&gt; www_users [44] =&gt; zformulamaster [45] =&gt; zpackmaster)
答案 0 :(得分:2)
您可以像这样访问数组键:
file.close()
首先检查foreach ($array as $key => $value)
,您的价值如何打印。然后将代码更改为以下内容。
var_dump($tables->result())
答案 1 :(得分:0)
在foreach循环和optin属性中使用这些
<?php foreach($tabls as $tbl){ ?>
<option><?php echo $tbl;?></option>
<?php } ?>