<!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-Type" content="text/html; charset=iso-8859-1" /> <title>Test Document</title> <script language="javascript" type="text/javascript" src="datetimepicker.js"> //Date Time Picker script- by TengYong Ng of http://www.rainforestnet.com //Script featured on JavaScript Kit (http://www.javascriptkit.com) //For this script, visit http://www.javascriptkit.com </script> </head> <body> <?php include("./gcrFunction.php"); ?> <form method="post"> <table> <tr> <td width="747"> <p align="left"><span class="style4 style25 style28 style6">Generate Chargeback Report</span></p> <p align="left"><span class="style21 style29 style5">The Chargeback Reporter works in 2 steps.</span></p> </td> </tr> <tr><td><p> </p></td></tr> <tr> <td> <table width="648" border="0" align="center" cellpadding="1" cellspacing="0" bordercolor="#FFFFFf"> <tr> <td bgcolor="#99bebe" colspan="4"> <p align="left" class="style8 style7 style32"><strong> <span class="style21 style33 style11">Step 1: Select Start and End Date</span></strong></p> </td> </tr> <tr> <td width="100" bgcolor="#99bebe" scope="row"> <div align="left" class="style8 style7 style31 style29 style13"> <div align="right"><strong>Start Date: </strong></div> </div> </td> <td width="220" bgcolor="#99bebe"> <input name="sDate" id="sDate" type="text" size="25"> <a href="javascript:NewCal('sDate','ddmmyyyy')"> <img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a Start Date"> </a> </td> <td width="100" bgcolor="#99bebe" scope="row"> <div align="left" class="style8 style7 style31 style29 style13"> <div align="right"><strong>End Date: </strong></div> </div> </td> <td width="220" bgcolor="#99bebe"> <input name="eDate" id="eDate" type="text" size="25"> <a href="javascript:NewCal('eDate','ddmmyyyy')"> <img src="images/cal.gif" width="16" height="16" border="0" alt="Pick an End Date"> </a> </td> </tr> <tr> <td bgcolor="#99bebe" colspan="4"> <p align="left" class="style5"> <span class="style21 style30 style11">Step 2: Generate the Chargeback Report </span></p> </td> </tr> <tr> <td bgcolor="#99bebe"><p> </p></td> <td bgcolor="#99bebe" colspan="3"> <div align="left"> <strong> <input type="submit" value="Generate" name="btnSubmit" /> </strong> </div> </td> </tr> </table> </td> </tr> </table> </form> <? validateData(); ?> </body> </html>
<? include('./connect.php'); error_reporting(E_ALL ^ E_NOTICE); function validateData() { global $conn; $sDate=$_POST['sDate']; $eDate=$_POST['eDate']; //echo $sDate; //echo $eDate; $btn=$_POST['btnSubmit']; if(isset($btn)) { if(!$sDate) { echo '<center><font face=Verdana color=Red size="2"><b>Start Date field is empty!</b></font></center></td> </tr><tr bgcolor="#ffffff"><td> <table width="760" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFf"> <tr><td width="760" bgcolor="#336666" scope="col"> </td></tr></table></td></tr><tr bgcolor="#ffffFF"> <td><p align="center" class="style30 style4" >©ITT Department, Petrotrin. </p></td></tr></table>'; die("Problem 1"); } else if(!$eDate) { echo '<center><font face=Verdana color=Red size="2"><b>End Date field is empty!</b></font></center></td> </tr><tr bgcolor="#ffffff"><td> <table width="760" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFf"> <tr><td width="760" bgcolor="#336666" scope="col"> </td></tr></table></td></tr><tr bgcolor="#ffffFF"> <td><p align="center" class="style30 style4" >©ITT Department, Petrotrin. </p></td></tr></table>'; die("Problem 2"); } else { function parseCSVComments($comments) { // First off escape all " and make them "" $comments = str_replace('"', '""', $comments); if(eregi(",", $comments) or eregi("\n", $comments)) { // Check if I have any commas or new lines return '"'.$comments.'"'; // If I have new lines or commas escape them } else { return $comments; // If no new lines or commas just return the value } } // Start our query of the database $sql = mysql_query("SELECT * FROM tsttbills where date between '$sDate' and '$eDate'", $conn) ; $numberFields = mysql_num_fields($sql); // Find out how many fields we are fetching if($numberFields) { // Check if we need to output anything for($i=0; $i<$numberFields; $i++) { // Create the headers for each column, this is the field name in the database $head[] = mysql_field_name($sql, $i); } $headers = join(',', $head)."\n"; // Make our first row in the CSV while($info = mysql_fetch_object($sql)) { foreach($head as $fieldName) { // Loop through the array of headers as we fetch the data $row[] = parseCSVComments($info->$fieldName); } // End loop $data .= join(',', $row)."\n"; // Create a new row of data and append it to the last row $row = ''; // Clear the contents of the $row variable to start a new row } // Start our output of the CSV $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/x-msdownload"); header("Content-Disposition: attachment; filename=".$filename.".csv"); header("Pragma: no-cache"); header("Expires: 0"); echo $headers.$data; } else { // Nothing needed to be output. Put an error message here or something. echo ("There is no data to create a CSV file."); } } //close the else }//close the if(isset($btn)) statement } ?>
$head[] = mysql_field_name($sql, $i); gonna have to try that.
<? include("./gcrFunction.php"); if(count($_POST) == 0) { ?> <!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-Type" content="text/html; charset=iso-8859-1" /> <title>Test Document</title> <script language="javascript" type="text/javascript" src="datetimepicker.js"> //Date Time Picker script- by TengYong Ng of http://www.rainforestnet.com //Script featured on JavaScript Kit (http://www.javascriptkit.com) //For this script, visit http://www.javascriptkit.com </script> </head> <body> <form method="post" target="_blank"> <table> <tr> <td width="747"> <p align="left"><span class="style4 style25 style28 style6">Generate Chargeback Report</span></p> <p align="left"><span class="style21 style29 style5">The Chargeback Reporter works in 2 steps.</span></p> </td> </tr> <tr><td><p> </p></td></tr> <tr> <td> <table width="648" border="0" align="center" cellpadding="1" cellspacing="0" bordercolor="#FFFFFf"> <tr> <td bgcolor="#99bebe" colspan="4"> <p align="left" class="style8 style7 style32"><strong> <span class="style21 style33 style11">Step 1: Select Start and End Date</span></strong></p> </td> </tr> <tr> <td width="100" bgcolor="#99bebe" scope="row"> <div align="left" class="style8 style7 style31 style29 style13"> <div align="right"><strong>Start Date: </strong></div> </div> </td> <td width="220" bgcolor="#99bebe"> <input name="sDate" id="sDate" type="text" size="25"> <a href="javascript<b></b>:NewCal('sDate','ddmmyyyy')"> <img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a Start Date"> </a> </td> <td width="100" bgcolor="#99bebe" scope="row"> <div align="left" class="style8 style7 style31 style29 style13"> <div align="right"><strong>End Date: </strong></div> </div> </td> <td width="220" bgcolor="#99bebe"> <input name="eDate" id="eDate" type="text" size="25"> <a href="javascript<b></b>:NewCal('eDate','ddmmyyyy')"> <img src="images/cal.gif" width="16" height="16" border="0" alt="Pick an End Date"> </a> </td> </tr> <tr> <td bgcolor="#99bebe" colspan="4"> <p align="left" class="style5"> <span class="style21 style30 style11">Step 2: Generate the Chargeback Report </span></p> </td> </tr> <tr> <td bgcolor="#99bebe"><p> </p></td> <td bgcolor="#99bebe" colspan="3"> <div align="left"> <strong> <input type="submit" value="Generate" name="btnSubmit" /> </strong> </div> </td> </tr> </table> </td> </tr> </table> </form> </body> </html> <? } validateData(); ?>
<? include("inc/functions.inc"); $conn = mysql_dbconn(); error_reporting(E_ALL ^ E_NOTICE); function validateData() { global $conn; $sDate=$_POST['sDate']; $eDate=$_POST['eDate']; //echo $sDate; //echo $eDate; $btn=$_POST['btnSubmit']; if(isset($btn)) { if(!$sDate) { echo '<center><font face=Verdana color=Red size="2"><b>Start Date field is empty!</b></font></center></td> </tr><tr bgcolor="#ffffff"><td> <table width="760" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFf"> <tr><td width="760" bgcolor="#336666" scope="col"> </td></tr></table></td></tr><tr bgcolor="#ffffFF"> <td><p align="center" class="style30 style4" >©ITT Department, Petrotrin. </p></td></tr></table>'; die("Problem 1"); } else if(!$eDate) { echo '<center><font face=Verdana color=Red size="2"><b>End Date field is empty!</b></font></center></td> </tr><tr bgcolor="#ffffff"><td> <table width="760" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFf"> <tr><td width="760" bgcolor="#336666" scope="col"> </td></tr></table></td></tr><tr bgcolor="#ffffFF"> <td><p align="center" class="style30 style4" >©ITT Department, Petrotrin. </p></td></tr></table>'; die("Problem 2"); } else { function parseCSVComments($comments) { // First off escape all " and make them "" $comments = str_replace('"', '""', $comments); if(eregi(",", $comments) or eregi("\n", $comments)) { // Check if I have any commas or new lines return '"'.$comments.'"'; // If I have new lines or commas escape them } else { return $comments; // If no new lines or commas just return the value } } // Start our query of the database $sql = mysql_query("SELECT * FROM tsttbills where date between '$sDate' and '$eDate'", $conn) ; $numberFields = mysql_num_fields($sql); // Find out how many fields we are fetching if($numberFields) { // Check if we need to output anything for($i=0; $i<$numberFields; $i++) { // Create the headers for each column, this is the field name in the database $head[] = mysql_field_name($sql, $i); } $headers = join(',', $head)."\n"; // Make our first row in the CSV while($info = mysql_fetch_object($sql)) { foreach($head as $fieldName) { // Loop through the array of headers as we fetch the data $row[] = parseCSVComments($info->$fieldName); } // End loop $data .= join(',', $row)."\n"; // Create a new row of data and append it to the last row $row = ''; // Clear the contents of the $row variable to start a new row } // Start our output of the CSV $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/x-msdownload"); header("Content-Disposition: attachment; filename=".$filename.".csv"); header("Pragma: no-cache"); header("Expires: 0"); echo $headers.$data; } else { // Nothing needed to be output. Put an error message here or something. echo ("There is no data to create a CSV file."); } } //close the else }//close the if(isset($btn)) statement } ?>
liked the way you used
$head[] = mysql_field_name($sql, $i); gonna have to try that.
<? include("./gcrFunction.php"); if(count($_POST[]) == 0) { ?>
$filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/x-msdownload"); header("Content-Disposition: attachment; filename=".$filename.".csv"); header("Pragma: no-cache"); header("Expires: 0");
Yea, I did and there's still a blank page...
from the file testGCR.php....with the following piece of code....isn't there supposed to be an open and closed square brackets?
php Syntax (Toggle Plain Text)
<? include("./gcrFunction.php"); if(count($_POST[]) == 0) { ?>
| DaniWeb Message | |
| Cancel Changes | |