Welcome Guest, Not a member yet? Register   Sign In
about database and loop
#1
Bug 
(This post was last modified: 06-01-2020, 10:32 AM by mjamilasfihani.)

I have some data in my database :

Code:
|---|--------------|----------------|
|id | country_code |     province   |
|---|--------------|----------------|
|11 |      ID      | Aceh           |
|12 |      ID      | Sumatera Barat |
.....................................
........ Long until 32 data .........

I call all the data where :
Code:
country_code = session()->getFlashdata('customer.addr_country')

And loop them, because I want to display in view with form_dropdown() and old() function.
I create the loop like this :
PHP Code:
$_list_province = ['HIDE_' => 'Provinsi'];

if (
$_temp_id[1] = session()->getFlashdata('customer.addr_country'))
{
    foreach (
$continueSignUpModel->model_01($_temp_id[1]) as $row)
    {
        
$_list_province += [$row['id'] => $row['province']];
    }

    
$_list_province array_merge($_list_province);


The $row['province] show the province that listed in database (where country_code), but the $row['id'] can not display from 11, 12, ... (as in database)
it shows number from 0,1,2,3 .... until end. I think its not good, because I need the $row['id'] display data from database (11,12, ...)

this is some of the output
Code:
<option value="" hidden="" >Provinsi</option>
<option value="0">Aceh</option>
<option value="1">Bali</option>

if I do or try to array it again
PHP Code:
$_list_province array_merge([$_list_province]); 

it show :
Code:
<optgroup label="0">
<option value="HIDE_">Provinsi</option>
<option value="11">Aceh</option>
<option value="51">Bali</option>
Reply
#2

I got the problem, form_dropdown() function change the number become reorder again from 0 until end. I try add "_" character before $row['id'] and it shows the number with good (I don't use optgroup)
Reply




Theme © iAndrew 2016 - Forum software by © MyBB