Hi i have some data which coming out from database in form of table like thisimage, first i match some data with searching and then display it on page now i need to download it as csv file format please help me check my code and i'm new in php. please check image too for the reference and please please help me
//import.php
// echo "<pre>";
//print_r($_POST);die();
$keyword = $_POST['keyword'];
$csvname = $_POST['csv_file'];
?>
<table border ="1">
<thead>
<tr>
<th>id</th>
<th>title</th>
<th>count</th>
</tr>
</thead>
<?php
$row = 0;
if (($handle = fopen("idata.csv", "r",)) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
// echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
// echo $data[$c] . "<br />\n";
$query = "SELECT * FROM wm_article WHERE id = '".$data[$c]."'";
$exec = mysqli_query($conn, $query);
$details = mysqli_fetch_array($exec);
$description = $details['title'] ." ".$details['description'];
//echo $description ;
// $regex = "/royal/";
// if (preg_match_all($regex, $description, $match))
// {
// print_r ($matches[0]);
// }
if(preg_match_all("/\b".$keyword."\b/i", $description, $match,PREG_OFFSET_CAPTURE, 3)){
// echo count(explode('royal', $description));
// echo "<pre>";print_r($match);
?>
<tr>
<td><?php echo $details['id'];?></td>
<td><a href ="<?php echo $details['url'];?>" target ="_blank"><?php echo $details['title'];?></a></td>
<td><?php echo count($match[0]); ?></td>
</tr>
<?php
}
}
}
}
?>
<?php
?>
</table>