Jump to content

[SOLVED] Dynamic HTML output saved to file


bajangerry

Recommended Posts

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>

 

Link to comment
Share on other sites

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>
";

Link to comment
Share on other sites

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);

?>

 

 

Link to comment
Share on other sites

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.