I have a table that shows all files from public/folder,
with format name 1_CCA-2018-0182224-720422085426
1_CCA-2018-0182224 this is ACCOUNT ID
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>
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
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.