Login   Register  
PHP Classes
elePHPant
Icontem

MySQL to Excel

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      MySql To Excel  >  All threads  >  MySQL to Excel  >  (Un) Subscribe thread alerts  
Subject:MySQL to Excel
Summary:Output MySQL to Excel file
Messages:1
Author:Brian Pitkin
Date:2014-07-19 08:21:55
 

  1. MySQL to Excel   Reply   Report abuse  
Picture of Brian Pitkin
Brian Pitkin
2014-07-19 08:21:55
I've inherited this php code which outputs CSV to screen. I'd like to output to an Excel file. Please would you tell me how?

<?php

// include select case to sort members list

if (!isset($_GET['sort'])) {
$sort = "m1.name";

} else {

switch ($_GET['sort']) {

case "name":
$sort="m1.name";
break;

case "email":
$sort="m1.email";
break;

case "level":
$sort="m2.user_level";
break;

case "type":
$sort="m1.membership_type";
break;

case "number":
$sort="m1.bsoup_no";
break;
}
}



mysql_select_db($database_BSoUP, $BSoUP);
$query_rsMembers = "SELECT m1.name, m1.bsoup_no, m1.membership_type, m2.id, m1.id as check_id, m2.user_level, m2.member_since, m2.first_name, m2.last_name, m1.email, m2.renewal FROM member_check m1 LEFT JOIN members m2 ON m1.email = m2.email ORDER BY name ASC";
$rsMembers = mysql_query($query_rsMembers, $BSoUP) or die(mysql_error());
$row_rsMembers = mysql_fetch_assoc($rsMembers);
$totalRows_rsMembers = mysql_num_rows($rsMembers);

mysql_select_db($database_BSoUP, $BSoUP);
$query_rsNonMembers = "SELECT m1.* FROM members m1 LEFT JOIN member_check m2 ON m1.email = m2.email WHERE m2.email IS NULL AND m1.email <> 'committee'";
$rsNonMembers = mysql_query($query_rsNonMembers, $BSoUP) or die(mysql_error());
$row_rsNonMembers = mysql_fetch_assoc($rsNonMembers);
$totalRows_rsNonMembers = mysql_num_rows($rsNonMembers);



?>

<?php do { ?>
<tr>


<td width="96%" colspan="6" align="left" valign="middle"><span class="medium"><?php echo $row_rsMembers['name']; ?>;<?php echo $row_rsMembers['email']; ?>;<?php echo $row_rsMembers['renewal']; ?></span></td></tr>
<?php } while ($row_rsMembers = mysql_fetch_assoc($rsMembers)); ?>

<?php
mysql_free_result($rsMembers);

mysql_free_result($rsNonMembers);
?>