bajangerry Posted January 15, 2008 Share Posted January 15, 2008 Guys, I have a webpage that displays data from a mysql database in a table that I would like to be able to save to a file in the HTML format. (See below) Can anyone explain to me how to do this? I have been able to save to file but not when it is dynamic HTML output. ?php include("lib/connect.inc.php"); if (date("m") == 1) {$test = 12;} else {$test = (date("m")-1);} $rowno = 0; $query = "SELECT * FROM import WHERE calledno not like ''AND month like '$test'"; $result = mysql_query($query); ?> <html> <head> <title>SMDR reporting</title> <style type="text/css"> <!-- table { background-color:#FFF; width:100%; border-collapse:collapse; } /* and of course a default one */ td { background-color:#FFF; border:1px solid black; padding:5px; } --> </style> </head> <body> <table> <tr> <td nowrap><div align="center"> <font size="-1"><strong>Row#</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Month</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Day</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Time</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Call Length</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Caller</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Code</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Called No</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Line</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Transferred</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Account Code</strong></font></div></td> </tr> <?php while($row = mysql_fetch_object($result)) { $rowno += 1; ?> <tr> <td><div align="center"><font size="-1"><?php echo ($rowno);?></font></div></td> <td><div align="center"><font size="-1"><?php echo ($row->month);?></A></font></div></td> <td><div align="center"><font size="-1"><?php echo ($row->day); ?></font></div></td> <td><div align="center"><font size="-1"><?php echo ($row->time);?><?php echo ($row->PM); ?></font></div></td> <td><div align="center"><font size="-1"><?php echo ($row->hrs);?>:<?php echo ($row->mins);?>:<?php echo ($row->sec); ?></fo$ <td><div align="center"><font size="-1"><?php echo ($extprint->name);?> <?php echo ($row->callingparty);?></a></font></div>$ <td><div align="centre"><font size="-1"><?php echo ($row->leaddigit); ?></font></div></td> <td><div align="center"><font size="-1"><?php echo ($row->calledno); ?></font></div></td> <td><div align="center"><font size="-1"><?php echo ($row->calledparty); ?></font></div></td> <td><div align="center"><font size="-1"><?php echo ($row->transferext); ?></font></div></td> <td><div align="center"><font size="-1"><?php echo ($row->accountcode); ?></font></div></td> </tr> <?php } ?> </table> <p align="center"> </p> </body> </html> Quote Link to comment Share on other sites More sharing options...
tinker Posted January 15, 2008 Share Posted January 15, 2008 Instead of escaping from php to html, treat all of the 'html' as a string, you can then write this to a file. Either do in sections or all as one? $s = " <table> <tr> <td nowrap><div align="center"> <font size="-1"><strong>Row#</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Month</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Day</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Time</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Call Length</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Caller</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Code</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Called No</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Line</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Transferred</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Account Code</strong></font></div></td> </tr> "; Quote Link to comment Share on other sites More sharing options...
bajangerry Posted January 15, 2008 Author Share Posted January 15, 2008 Tinker, thanks for that. The output loops through rows to produce the table, will that still work? Quote Link to comment Share on other sites More sharing options...
bajangerry Posted January 15, 2008 Author Share Posted January 15, 2008 hmmm.... I put the $s = " before the HTML code and the output file just had the exact HTML code in it rather than the output webpage. Seems as if I may be putting it in the wrong location maybe? Quote Link to comment Share on other sites More sharing options...
tinker Posted January 15, 2008 Share Posted January 15, 2008 it is html code, it's only when a web browser renders it that it's in the form you want. Just think how do all the images and includes get downloaded, the scripts interpreted, etc, the browser performs a lot of magic! Quote Link to comment Share on other sites More sharing options...
bajangerry Posted January 15, 2008 Author Share Posted January 15, 2008 No, I mean that the code that I showed is what is in the output file. The programming code I mean not the HTML result of the program. Quote Link to comment Share on other sites More sharing options...
tinker Posted January 15, 2008 Share Posted January 15, 2008 i'm a little bit lost, maybe this might help... eval Quote Link to comment Share on other sites More sharing options...
bajangerry Posted January 15, 2008 Author Share Posted January 15, 2008 Tinker, Sorry, I may have been wrong in what I said earlier. I have though found a means of doing what I wish with the following code but thank you very much for your assistance: <?php include("lib/connect.inc.php"); if (date("m") == 1) {$test = 12;} else {$test = (date("m")-1);} $rowno = 0; $query = "SELECT * FROM import WHERE calledno not like ''AND month like '1'"; $result = mysql_query($query); ?> <? ob_start(); //Start object buffering before any output ?> <html> <head> <title>SMDR reporting</title> <style type="text/css"> <!-- table { background-color:#FFF; width:100%; border-collapse:collapse; } /* and of course a default one */ td { background-color:#FFF; border:1px solid black; padding:5px; } --> </style> </head> <body> <table> <tr> <td nowrap><div align="center"> <font size="-1"><strong>Row#</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Month</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Day</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Time</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Call Length</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Caller</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Code</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Called No</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Line</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Transferred</strong></font></div></td> <td nowrap><div align="center"> <font size="-1"><strong>Account Code</strong></font></div></td> </tr> <? while($row = mysql_fetch_object($result)) { $rowno += 1; ?> <tr> <td><div align="center"><font size="-1"><?php echo ($rowno);?></font></div></td> <td><div align="center"><font size="-1"><?php echo ($row->month);?></A></font></div></td> <td><div align="center"><font size="-1"><?php echo ($row->day); ?></font></div></td> <td><div align="center"><font size="-1"><?php echo ($row->time);?><?php echo ($row->PM); ?></font></div></td> <td><div align="center"><font size="-1"><?php echo ($row->hrs);?>:<?php echo ($row->mins);?>:<?php echo ($row->sec); ?></fo$ <td><div align="center"><font size="-1"><?php echo ($extprint->name);?> <?php echo ($row->callingparty);?></a></font></div>$ <td><div align="centre"><font size="-1"><?php echo ($row->leaddigit); ?></font></div></td> <td><div align="center"><font size="-1"><?php echo ($row->calledno); ?></font></div></td> <td><div align="center"><font size="-1"><?php echo ($row->calledparty); ?></font></div></td> <td><div align="center"><font size="-1"><?php echo ($row->transferext); ?></font></div></td> <td><div align="center"><font size="-1"><?php echo ($row->accountcode); ?></font></div></td> </tr> <? } ?> </table> <p align="center"> </p> </body> </html> <? $output = ob_get_contents(); //Copy all output to a var ob_end_flush(); //Stop buffering and send content to the browser $fp = fopen('myfile.txt', 'w'); //Open myfile.txt for writing fwrite($fp, $output); //Write the content to the file fclose($fp); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.