【发布时间】:2019-08-05 04:18:30
【问题描述】:
我不知道如何获取 ID 以导出记录。
我有一个下拉按钮,其中包含三个选项(导入、导出和创建新用户)。单击导出按钮后,选中复选框的记录应导出为 CSV 文件。
按钮的外观:
我有导出 CSV 文件的代码,但我无法获取复选框的 ID。
导出 CSV 文件代码(工作正常):
public function export_csv($param = '')
{
$filename = strtotime("now"). ".csv";
$delimiter = ",";
// Create a file pointer
$f = fopen('php://memory', 'w');
// Set column headers
$fields = array('Id', 'Name', 'Email', 'Phone', 'Created', 'Status');
fputcsv($f, $fields, $delimiter);
$lineData = array(1,'34',$param,'859685968','29-09-2019','online');
fputcsv($f, $lineData, $delimiter);
// Move back to beginning of file
fseek($f, 0);
ob_clean();
// Set headers to download file rather than displayed
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="' . $filename . '";');
// Output all remaining data on a file pointer
fpassthru($f);
// Exit from file
exit();
}
HTML 表格如下所示:
<table class="table">
<thead>
<tr>
<th style="width: 2%;"><input type="checkbox" name="select_all" id="select_check" class="checkbox select_check" ></th>
<th style="width: 18%;">الاسم</th>
<th style="width: 5%;"></th>
<th style="width: 25%;">البريد الالكتروني</th>
<th style="width: 20%;">مدينة</th>
<th style="width: 20%;">اخر ظهور</th>
<th style="width: 50%;">زيارات الموقع</th>
</tr>
</thead>
<tbody>
<?php if (count($all_visitors) > 0): ?>
<?php foreach($all_visitors as $visitor) : ?>
<form method="POST">
<tr>
<td><input type="checkbox" name="select_checkbox[]" id="select_checkbox" class="checkbox selectall_checkbox" value="<?=$visitor['id']?>"></td>
<td><?= !empty($visitor['full_name']) ? $visitor['full_name'] : 'الاسم لم يعطى حتى الان'?></td>
<td><a href="<?= BASE_URL.'chats?id='.$visitor['unique_id']?>" style="<?= empty($visitor["chat_id"]) ? " pointer-events: none;cursor: default;" :''?>"><i class="fa fa-comments" aria-hidden="true"></i></a> </td>
<td><?= !empty($visitor['email']) ? $visitor['email'] : 'البريد الإلكتروني لم يعطى حتى الان'?></td>
<td><?= !empty($visitor['city']) ? $visitor['city'] : 'لم يتم إعطاء المدينة بعد'?></td>
<td><?= !empty($visitor['updated']) ? get_timeago(strtotime($visitor['updated'])) : '30 Seconds ago'?></td>
<td class="site-visits" ><?= !empty($visitor['total_visits']) ? $visitor['total_visits'] : '0'?></td>
</tr>
</form>
<?php endforeach; ?>
<?php else:?>
<tr><td colspan="6">No records found</td></tr>
<?php endif; ?>
</tbody>
</table>
【问题讨论】:
标签: php html codeigniter