Я сделал страницу в php, которая показывает некоторые данные пользователей, такие как имя, адрес электронной почты и т. Д. В разных столбцах. Данные поступают из базы данных. Теперь я хочу экспортировать всю информацию в CSV-файл, есть ли какое-либо решение для него в php.
Ниже приведен код, отображающий данные на странице.Экспорт данных в файл csv в php
<table width='98%' align="center" id='Categories_Main' cellspacing='0' cellpadding='0' class="table table-striped">
<tr height="25">
<th class="cat_list" colspan="4"><br /><?php echo $this->db->get_modules($cid);?><br /><br /></th>
<th></th>
</tr>
<tr>
<th width="150" style="min-width:55px" class="nowrap center"><a class="hasTip">Gender </a></th>
<th width="150" style="min-width:55px" class="nowrap center"><a class="hasTip">Name</a></th>
<th width="150" style="min-width:55px" class="nowrap center"><a class="hasTip">Adress</a></th>
<th width="150" style="min-width:55px" class="nowrap center"><a class="hasTip">Email</a></th>
<th width="150" style="min-width:55px" class="nowrap center"><a class="hasTip">Number</a></th>
<th width="150" style="min-width:55px" class="nowrap center"><a class="hasTip">Course</a></th>
<th width="150" style="min-width:55px" class="nowrap center"><a class="hasTip">Price</a></th>
<th width="150" style="min-width:55px" class="nowrap center"><a class="hasTip">Action</a></th>
</tr>
<?php
$sql = "SELECT * FROM
prospective_request
ORDER BY name ASC limit $st,$limit";
$this->db->query($sql);
while($this->db->fetch_array())
{
?>
<th class="nowrap has-context" width="200" style="min-width:55px">
<div class="pull-left"> <p style='margin-left: 10px; text-align:center'><?php echo showLink($this->db->record['user_title'],"?module=prospective_request&func=view&page=$page&cid=".$this->db->record['id'], $this->db->record['id']);?>
</p></div></th>
<th class="nowrap has-context" width="200" style="min-width:55px">
<div class="pull-left"> <p style='margin-left: 10px; text-align:center'><?php echo showLink($this->db->record['name'],"?module=prospective_request&func=view&page=$page&cid=".$this->db->record['id'], $this->db->record['id']);?>
</p></div></th>
<th class="nowrap has-context" width="200" style="min-width:55px">
<div class="pull-left"> <p style='margin-left: 10px; text-align:center'><?php echo showLink($this->db->record['address'],"?module=prospective_request&func=view&page=$page&cid=".$this->db->record['id'], $this->db->record['id']);?>
</p></div></th>
<th class="nowrap has-context" width="200" style="min-width:55px">
<div class="pull-left"> <p style='margin-left: 10px; text-align:center'><?php echo showLink($this->db->record['email'],"?module=prospective_request&func=view&page=$page&cid=".$this->db->record['id'], $this->db->record['id']);?>
</p></div></th>
<th class="nowrap has-context" width="200" style="min-width:55px">
<div class="pull-left"> <p style='margin-left: 10px; text-align:center'><?php echo showLink($this->db->record['number'],"?module=prospective_request&func=view&page=$page&cid=".$this->db->record['id'], $this->db->record['id']);?>
</p></div></th>
<th class="nowrap has-context" width="200" style="min-width:55px">
<div class="pull-left"> <p style='margin-left: 10px; text-align:center'><?php echo showLink($this->db->record['course'],"?module=prospective_request&func=view&page=$page&cid=".$this->db->record['id'], $this->db->record['id']);?>
</p></div></th>
<th class="nowrap has-context" width="200" style="min-width:55px">
<div class="pull-left"> <p style='margin-left: 10px; text-align:center'><?php echo showLink($this->db->record['total_price'],"?module=prospective_request&func=view&page=$page&cid=".$this->db->record['id'], $this->db->record['id']);?>
</p></div></th>
<th class="tabletxt" width="200" style="min-width:55px"><p align='left'>
<?php
if($cid){
?>
<a href="javascript:changeStatus(<?php echo $this->db->record['id'];?>,<?php echo ($this->db->record['status']==1)?"0":"1";?>, <?php echo $this->db->record['parent_id'];?>,<?php echo $page; ?>);"><img src="images/<?php echo ($this->db->record['status']==1)?"active":"inactive";?>.gif" border="0" align="absbottom" alt="<?php echo ($this->db->record['status']==1)?"Active - Click to deactivate":"Inactive - Click to activate";?>" /></a>
<?php } //IF ?>
<a href="index.php?module=prospective_request&func=edit&page=<?php echo $page;?>&cid=<?php echo $this->db->record['id'];?>&pid=<?php echo $cid;?>"><img src="images/editrec.png" border="0" align="absbottom" alt="Edit Record" /></a> <a href="javascript:delete_module('<?php echo $this->db->record['id']; ?>', '<?php echo $page;?>')" title="Delect Record"><img src="images/delete.gif" border="0" align="absbottom" alt="Delete Record" /></a>
</p> </th>
</tr>
<?php
} //While
?>
<form name="frmChangeStatus" action="index.php?module=prospective_request&func=view&page=<?=$page?>&cid=<?=$_GET['cid'];?>" method="post" >
<input type="hidden" name="action" value="" />
<input name="cat_id" type="hidden" value="" />
<input name="prospective_request" type="hidden" value="" />
</form>
<tr>
<td class="sub" align="center" colspan="6">
<?php
pagination($numpages, $page, "?module=".$_GET['module']."&func=".$_GET['func']."&cid=".$cid);
?>
</td>
</tr>
</table>
Я надеюсь, что это поможет вам http://stackoverflow.com/questions/17362686/export-a-mysql-table-into-csv-using-php-code – Shafeeque
http://stackoverflow.com/questions/4249432/ export-to-csv-via-php –
http://www.daniweb.com/web-development/php/threads/362491/how-to-export-the-data-as-csv-file-from-mysql- in-php –