0

I have some data displayed on screen

php:

echo'
<script>
    $(document).ready(function(){
        window.print();
    });
</script>';
$sql="SOME QUERY";
$result=$conn->query($sql);
if($result->num_rows>0)
{
while($row=$result->fetch_assoc())
{
echo'<div id="one">
....content....
</div>';
echo'<div id="two">
....content....
</div>';
}
}

now when the page loads the whole page displayed gets printed ( as the function suggest in jquery), but is it possible to print #one on page 1 , and #two on next page (no matter how much content is in these division)

1 Answer 1

2

Create a page class for your elements, and add a page-break after them using CSS, so each will be printed to a new page

@media print {
    .page{page-break-after: always;}
}

And change the php code to:

while($row=$result->fetch_assoc())
{
echo'<div id="one" class="page">
....content....
</div>';
echo'<div id="two" class="page">
....content....
</div>';
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.