I'm stumped. I have a simple report that I want to save as an excel file. It should work but something isn't quite right and I can't spot it. It only prints the first record--even though without the excel headers, it works fine.

What am I missing here?

Thanks,

robkir

<?php
//session_start();
	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=2009_New_Referee_Signup_List.xls "); 
    header("Content-Transfer-Encoding: binary ");

include('../DBconMOD.php');

echo "2009 Games Completed <br />"; 


$result = mysql_query("SELECT * FROM ref_directory WHERE active = '1' ORDER BY nameL ");

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

?>			

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title></title>
<!-- <link rel="stylesheet" type="text/css" href="../../templates/master_style_sheet.css" /> -->
<style type="text/css">
.style1 {
	border-style: solid;
	border-width: 1px;
}
.style2 {
	border: 1px solid #000000;
	width: 10%;
}
.style3 {
	border: 1px solid #000000;
	width: 10%;
	text-align: center;
}
</style>
</head>

<body>



<?php 

$sal = $info['salutation'];
$first = $info['nameF'];
$last =$info['nameL'];

$refName = $sal . " " . $first . " " . $last ;

//what is primary phone number?

$phonePrimary = $info['phoneP'];

if($phonePrimary == '1') 
{
	$phone2Use = $info['phoneH'];
}

if($phonePrimary == '1') 
{
	$phone2Use = $info['phoneW'];
}

if($phonePrimary == '1') 
{
	$phone2Use = $info['phoneC'];
}

$ac = substr($phone2Use,0,3);
$district = substr($phone2Use,3,3);
$number = substr($phone2Use,6,4);

$email = $info['email1'];


$category = $info['cat'];
	if($category == '1')
		$category = "adult";

if($category == '2')
	$category = "Youth";


$rank = $info['rank'];
	if ($rank == '5' )
		$rankIs = "Reg"; 
	if ($rank == '4' )
		$rankIs = "Inter"; 
	if ($rank == '3' )
		$rankIs = "Adv"; 
	if ($rank == '2' )
		$rankIs = "Nat2"; 
	if ($rank == '1' )
		$rankIs = "Nat"; 
	if ($rank == '0' )
		$rankIs = "Not Rated"; 




$ref_since = $info['started'];
$rank = $info['rank'];
$rankMaxC = $info['rankMaxC'];
$rankMaxL = $info['rankMaxL'];

print $refName  . " | " . $category ." | " . $rankIs;

?>
<table style="width: 100%" class="style1">
	<tr class="small_type">
		<td class="style3" colspan="2"><strong>Under 8</strong></td>
		<td class="style3" colspan="2"><strong>Under 10</strong></td>
		<td class="style3" colspan="2"><strong>Under 12</strong></td>
		<td class="style3" colspan="2"><strong>Under 14</strong></td>
		<td class="style3" colspan="2"><strong>Upper Division</strong></td>
	</tr>
	<tr class="small_type">
		<td class="style3">Centers</td>
		<td class="style3">Lines</td>
		<td class="style3">Centers</td>
		<td class="style3">Lines</td>
		<td class="style3">Centers</td>
		<td class="style3">Lines</td>
		<td class="style3">Centers</td>
		<td class="style3">Lines</td>
		<td class="style3">Centers</td>
		<td class="style3">Lines</td>
	</tr>
	<tr>
		<td class="style2" style="height: 59px"></td>
		<td class="style2" style="height: 59px"></td>
		<td class="style2" style="height: 59px"></td>
		<td class="style2" style="height: 59px"></td>
		<td class="style2" style="height: 59px"></td>
		<td class="style2" style="height: 59px"></td>
		<td class="style2" style="height: 59px"></td>
		<td class="style2" style="height: 59px"></td>
		<td class="style2" style="height: 59px"></td>
		<td class="style2" style="height: 59px"></td>
	</tr>
</table>

</body>

</html>

<?php 	} ?>

    just calling an html file *.xls does not make it an xls file.

      It does, however, open up in an excel format--its just not putting all the records in from the while statement.

        it only opens excel as the os is only checking the file extension. you could save the output on your computer name the file *.xls and double click it. You need to either right an actual xls file or something else like csv.

          Maybe we could approach the problem from another way. This script creates a user form that is to be printed out. I want to have five records per page, but when I print it out, I get five and half records. That creates a readability problem.

          I have spent the morning trying to figure out who to get it break at the right point. For example, .break { page-break-before: always; }

          If I can solve this problem, I can skip the excel question.

          Can you help?

          But my knowledge isn't deep enough to make it all work.

            Your safest bet is to access the DB using Excel.

              Hi Bjom,
              That's an interesting suggestion--but I haven't got a clue how to do that. Could you point me to a website or two so I can investigate it?

              thanks

                Write a Reply...