0

Please anyone suggest how to display data in dropdown list? what code will be use in option attribute?

My Controller

public function tableReports()
{
    $data['tables']=$this->DbReports->selectTable('snehal_pharma');
    $this->load->view('reports/rpt.php');

}

Model Code

function selectTable($db)
    {
        $query=$this->db->list_tables();
        print_r($query);
        return $query;
    }

View

<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>

Output

Array ( [0] => account_groups [1] => account_undergroup [2] => batch_master [3] => batch_packing [4] => batch_stock [5] => company_master [6] => cost_sheet [7] => cost_sheet_details [8] => customer [9] => departments [10] => disp_material [11] => dm_gatepass [12] => equipment_master [13] => es_finance_master [14] => es_ledger [15] => es_voucher [16] => es_voucherentry [17] => exipient [18] => mail_date [19] => pm_issue [20] => purchase [21] => purchase_details [22] => purchase_indent [23] => purchase_items [24] => purchase_master [25] => purchase_order [26] => sales [27] => sales_details [28] => sales_items [29] => sales_master [30] => sop_master [31] => stock_register [32] => stockcategory [33] => stockmaster [34] => supplier_master [35] => supply_order [36] => taxcategories [37] => tbl_state [38] => tbluser [39] => unit_pack [40] => unitsofmeasure [41] => view_salesledger [42] => viewbatchstock [43] => www_users [44] => zformulamaster [45] => zpackmaster )

4
  • <option value="<?php echo $tbl;?>"><?php echo $tbl;?></option> Commented Aug 31, 2017 at 12:04
  • not working i tried Commented Aug 31, 2017 at 12:11
  • what you mean not working . is there any error ? Commented Aug 31, 2017 at 12:13
  • check my answer mam Commented Aug 31, 2017 at 12:24

2 Answers 2

2

You can access your array keys like so:

foreach ($array as $key => $value)

First check var_dump($tables->result()), How is your value printing. Then change your code to something like below.

<?php foreach($tables->result() as $key => $value){ ?>

<option value="<?php echo $key;?>"><?php echo $value;?></option>

<?php } ?>
Sign up to request clarification or add additional context in comments.

1 Comment

atleast you got the idea
0

use these in foreach loop and optin attribute

<?php foreach($tabls as $tbl){ ?>
    <option><?php echo $tbl;?></option>
<?php } ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.