0

I have a table that shows all files from public/folder,

with format name 1_CCA-2018-0182224-720422085426

  1. 1_CCA-2018-0182224 this is ACCOUNT ID

  2. 720422085426 this is ID NO

when user check the checkbox I want to save filename to 2 column (ACCOUNT ID & ID NO)
I Use hidden to get ID NO value, but the problem is, the value of ID NO is not match with filename,

if i thick the last record, ID NO will save ID NO before the last record,

but if thick the first record, ID NO save correctly,

can anyone help me?

<table id="dataTable" class="table table-bordered table-condensed table-hover table-striped" width="100%" border="1">
    <thead>
    <tr>
        <th width="5%">No</th>
        <th width="45%">Account ID & ID No</th>
        <th data-checkbox="true" width="5%"></th>
    </tr>
    </thead>
    <tbody>
    <?php $i = 1; ?>
    <tr>
        <td>1</td>
        <td>123</td>
        <td>
            <input type="checkbox" name="account_id[]" value="{{ substr($file,10,18) }}">
            <input type="hidden" name="file[]" value="{{$file}}">
            <input type="hidden" name="id[]" value="{{ substr($file,29,12) }}">
        </td>

    </tr>
    <tr>
        <td>2</td>
        <td>1234</td>
        <td>
            <input type="checkbox" name="account_id[]" value="{{ substr($file,10,18) }}">
            <input type="hidden" name="file[]" value="{{$file}}">
            <input type="hidden" name="id[]" value="{{ substr($file,29,12) }}">
        </td>

    </tr>
    <?php $i++; ?>
    </tbody>
</table>
Rwd
  • 34,180
  • 6
  • 64
  • 78
nvrzl
  • 103
  • 1
  • 3
  • 14

1 Answers1

0

You should be able to synchronize the data retrieval by using the following approach:

foreach($request->id as $key => $value) {
    $id = $value;
    $file = $request->file[$key];
    $accountId = $request->account_id[$key] ?? null;
    if ($accountId) {
        // do stuff if checkbox was ticked
    } else {
        // do stuff if checkbox wasn't ticked            
    }
}
user2094178
  • 9,204
  • 10
  • 41
  • 70