Adern Nerk
Adern Nerk

Reputation: 45

print the data on different pages in php using jquery

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)

Upvotes: 0

Views: 73

Answers (1)

Iter Ator
Iter Ator

Reputation: 9289

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>';
}

Upvotes: 2

Related Questions