Jump to content

rhodesa

Staff Alumni
  • Posts

    5,253
  • Joined

  • Last visited

Everything posted by rhodesa

  1. Also be aware, for this to work, the HTML content needs to be 100% valid. The majority of webpages on the internet are NOT valid HTML.
  2. If you have logins, I assume you have a database to track meta data about the user? Aka username, password, etc. Just add a new column for logins, and each time the login, increase the number.
  3. Well...the code you post looks fine, so it has to be something in the rest of your code. You'll need to post more of the code if you want me to try and find the problem.
  4. Also, just to make sure the problem is in your code and not your computer, click this link and tell me if it opens ok: http://vectorloft.com/aaron/phpfreaks/test.php
  5. But my concern is that something is being printed before this code. In the ExcelWriter class, update these lines: function send($filename = null){ if(headers_sent()) die("Headers already sent"); //Add this line if($filename){ header ( "Expires: Mon, 1 Apr 1974 05:00:00 GMT" );
  6. Is anything else getting echoed/printed? Because the excel can be the only thing sending stuff. Can you post some of your code?
  7. Add piece by piece to find your problem. First comment out the $excel->writeLine($myArr); inside the while loop and make sure that opens with just the headers then uncomment the above line and start with $myArr=array($id); in the while loop, testing and adding each column 1 by 1 then, let me know where it breaks
  8. Are you using the updated class that I posted? Here is the link again: http://www.phpfreaks.com/forums/index.php?action=dlattach;topic=180789.0;attach=3752
  9. Nope...don't do that...the version I posted is different... If you were more careful with your indenting, you would notice that echo is INSIDE the while loop: while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ .... $myArr=array($id,$product,$company,$description,$web,$last,$used,$active); $excel->writeLine($myArr); $excel->close(); echo "data is write into hr.xls Successfully."; } we don't want close() (no longer needed with my updated copy of ExcelWriter) and we don't want the echo, because the send() can be the only thing displaying output. Use this: <?php include "../includes/db_login.php"; include("../excel/excelwriter.inc.php"); $excel=new ExcelWriter(); $myArr=array("Id","Product","Company","Description","Web Address","Last Used","Where product was last use","Is product active or inactive?"); $excel->writeLine($myArr); $query = "SELECT * FROM $tablename"; $result = mysql_query($query); if(!$result){ die("Could not query the database: <br/>" . mysql_error()); } while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $id = $row['rowid']; $company = $row['company']; $product = $row['product']; $description = $row['description']; $web = $row['web']; $last = $row['last']; $used = $row['used']; $active = $row['active']; $myArr=array($id,$product,$company,$description,$web,$last,$used,$active); $excel->writeLine($myArr); } $excel->send('hr'); exit; ?>
  10. well...from a DB you would just do: <?php include("db.php"); //Connect to MySQL DB include("excelWriter.inc.php"); $excel=new ExcelWriter(); //Add Column Headers $excel->writeLine(array("FIELD 1","FIELD 2","FIELD 3")); //Add rows from Database $sql = "SELECT `field1`,`field2`,`field3` FROM `table` WHERE `type` = 'test'"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($result)){ //Feel free to manipulate the values here //Add row to excel $excel->writeLine(array($row['field1'],$row['field2'],$row['field3'])); } //Send file to browser $excel->send('filename'); //Automatically adds .xls ?>
  11. I just downloaded the copy from phpclasses and my version is a little different. I don't remember if I modified it or not, but it's attached here. (Note I renamed it to .txt so i could upload it.) Usage: <?php include("excelWriter.inc.php"); $excel=new ExcelWriter(); $myArr=array("Name","Last Name","Address","Age"); $excel->writeLine($myArr); $myArr=array("Sriram","Pandit","23 mayur vihar",24); $excel->writeLine($myArr); $myArr=array("Tapan","Chauhan","1st Floor Vasundhra",25); $excel->writeLine($myArr); $excel->send('filename'); //Automatically adds .xls ?> [attachment deleted by admin]
  12. Yeah...i usually use the $excel->writeLine($myArr); method. Look at the documentation, cus you can you have it dynamically generate the excel file and then send it to the browser for download instead of saving the file locally on the server.
  13. I use this one a lot: http://www.phpclasses.org/browse/package/2037.html
×
×
  • 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.