Printing a dynamic content
Posted: Thu Aug 11, 2011 9:06 am
Hello! Could anybody help me.
I want to allow the clients to print (send to printer) a dynamical content, created by php.
To do this I created the javascript function:
<script type="text/javascript">
function printit()
{
var d = window.open();
d.document.open();
d.document.write("<html>\n<head>\n<title>To Print</title>\n</head>\n"+
"<body>\n"+
"<?php
$file_array = file('files/goods.txt');
$ad = explode('|',$file_array[0]);
echo '<table width = \"100%\" border = \"1\" class=\"goods\">';
echo '<tr>';
for($i=1; $i < (count($file_array)-1); $i++)
{
$ad = explode('|',$file_array[$i]);
echo '<tr>';
for($j=0; $j < count($ad); $j++)
{
echo '<td >';
echo $ad[0]; /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!THE TROUBLE IS HERE!!!!!!!!!!!!!!!!!!!!!!!! */
echo '</td >';
}
echo '</tr>';
}
echo '</table>';
?>"+
"</body>\n</html>\n");
d.document.close();
d.print();
}
</script>
I call the function in this way:
echo '<input type="button" value="To print" onclick="printit()"/><br />';
All works fine while I did not use variable index in that line, when I try to use $ar[$j] - the function doesn't work!
I cannot imagine where is the problem. Why $ar[0] works fine and $ar[$i] does not work?
I simplyfied the function for the example, in fact it uses inserted loops to read txt file into a table.
Sorry for my English, I did not find any answer on Russian forums, so I decided to try here.
I want to allow the clients to print (send to printer) a dynamical content, created by php.
To do this I created the javascript function:
<script type="text/javascript">
function printit()
{
var d = window.open();
d.document.open();
d.document.write("<html>\n<head>\n<title>To Print</title>\n</head>\n"+
"<body>\n"+
"<?php
$file_array = file('files/goods.txt');
$ad = explode('|',$file_array[0]);
echo '<table width = \"100%\" border = \"1\" class=\"goods\">';
echo '<tr>';
for($i=1; $i < (count($file_array)-1); $i++)
{
$ad = explode('|',$file_array[$i]);
echo '<tr>';
for($j=0; $j < count($ad); $j++)
{
echo '<td >';
echo $ad[0]; /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!THE TROUBLE IS HERE!!!!!!!!!!!!!!!!!!!!!!!! */
echo '</td >';
}
echo '</tr>';
}
echo '</table>';
?>"+
"</body>\n</html>\n");
d.document.close();
d.print();
}
</script>
I call the function in this way:
echo '<input type="button" value="To print" onclick="printit()"/><br />';
All works fine while I did not use variable index in that line, when I try to use $ar[$j] - the function doesn't work!
I cannot imagine where is the problem. Why $ar[0] works fine and $ar[$i] does not work?
I simplyfied the function for the example, in fact it uses inserted loops to read txt file into a table.
Sorry for my English, I did not find any answer on Russian forums, so I decided to try here.