Jump to content

Recommended Posts

I have a PHP file that downloads an XLS file showing the data from a database. It currently shows whether an individual has registered for a golf tournament (either 0 or 1) which is a subset of the overall registration for the conference. What I would like is to have an XLS file that lists only those users who have registered for the golf option (not a list of all registrants with a 0 or 1 next to golf).

 

-----

 

The following is part of the code I have that works but not how I want it to work:

 

$db = mysql_select_db ($db_name, $connection) or die (mysql_error());

 

 

// Get data records from table.

 

$sql = "SELECT lastname, firstname, MI, badgename, mailingaddress, city, stateprov, zippostal, rotaryclub, classification, email, password, homephone, workphone, cellphone, rotarian, rotaractor, interactor, pastdistgov, clubpres, clubpreselect, clubpastpres, clubsecretary, pioneer, paulharrisfellow, benefactor, guestlastname, guestfirstname, guestMI, guestbadgename, guestrot, guestpaul, guestbene, hosting, numattendees, lunchsat, guestlunchsat, dinnersat, guestdinnersat, qtyA, qtyB, qtyC, qtyD, qtyE, qtyF, qtyG, qtyH, qtyI, totalA, totalB, totalC, totalD, totalE, totalF, totalG, totalH, totalI, grandtotal FROM 2008registration";

 

$result = @mysql_query($sql, $connection) or die(mysql_error());

 

 

// Functions for export to excel.

 

function xlsBOF() {

 

echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);

 

return;

 

}

 

 

function xlsEOF() {

 

echo pack("ss", 0x0A, 0x00);

 

return;

 

}

 

 

function xlsWriteNumber($Row, $Col, $Value) {

 

echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);

 

echo pack("d", $Value);

 

return;

 

}

 

 

function xlsWriteLabel($Row, $Col, $Value ) {

 

$L = strlen($Value);

 

echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);

 

echo $Value;

 

return;

 

}

 

 

header("Pragma: public");

 

header("Expires: 0");

 

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

 

header("Content-Type: application/force-download");

 

header("Content-Type: application/octet-stream");

 

header("Content-Type: application/download");;

 

header("Content-Disposition: attachment;filename=golf.xls ");

 

header("Content-Transfer-Encoding: binary ");

 

 

xlsBOF();

 

 

/*

 

Make a top line on your excel sheet at line 1 (starting at 0).

 

The first number is the row number and the second number is the column, both are start at '0'

 

*/

 

 

xlsWriteLabel(0,0,"Registered Members");

 

 

// Make column labels. (at line 3)

 

xlsWriteLabel(2,0,"Last Name");

 

xlsWriteLabel(2,1,"First Name");

 

xlsWriteLabel(2,2,"Golf");

 

 

$xlsRow = 3;

 

 

// Put data records from mysql by while loop.

 

while($row=mysql_fetch_array($result)){

 

 

xlsWriteLabel($xlsRow,0,$row['lastname']);

 

xlsWriteLabel($xlsRow,1,$row['firstname']);

 

xlsWriteLabel($xlsRow,2,$row['qtyB']);

 

$xlsRow++;

 

}

 

xlsEOF();

 

exit();

 

-----

 

Any help would be greatly appreciated.

 

Thanks,

T

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.