hello dani and everyone here..

please help..
i try to create my own page number on my php file..
each pages, i wanna have page number at the bottom right..
some page call from the database.. so we dono how many pages it will take..
do u have any idea how to create it?
what languange should be use?
php? javascript? ..?
please help..

thank u

Dani AI

Generated

Briefly: it depends what you mean by “page.” If each include is one logical page, a running counter is enough. If content length (DB rows, images, long tables) can make an include span several printed pages, you need a rendering approach that knows physical pages (PDF or browser print with paged-media).

’s suggestion of a counter is the right idea when includes equal pages. A safer pattern is a small wrapper that captures an include, appends a footer, and advances the counter. Example wrapper (assumes includes are fragments, not full <html> pages):

<?php
$pageNum = 1;

function include_with_pagenumber($file) {
    global $pageNum;
    ob_start();
    include $file;
    $block = ob_get_clean();

    $footer = '<div style="text-align:right;font-size:12px;margin-top:8px;">Page ' . $pageNum . '</div>';
    if (stripos($block, '</body>') !== false) {
        $block = preg_replace('/<\/body>/i', $footer . '</body>', $block, 1);
    } else {
        $block .= $footer;
    }

    echo $block;
    $pageNum++;
}
?>

If your pages are produced by paginating DB results, compute total pages on the server and render “Page X of Y” for each page (calculate total from the row count and your rows-per-page). For printed/PDF output where “physical” page numbers must be accurate, use a PDF renderer (mPDF/ TCPDF / wkhtmltopdf / headless Chrome). Example (mPDF):

$mpdf = new \Mpdf\Mpdf();
$mpdf->SetHTMLFooter('<div style="text-align:right;">Page {PAGENO} of {nb}</div>');
$mpdf->WriteHTML($fullReportHtml);
$mpdf->Output();

Troubleshooting & best practices: keep included pieces as fragments so the wrapper can inject footers; avoid injecting into includes that already contain full <html> wrappers; control breaks with page-break-inside: avoid / break-inside: avoid for blocks you don’t want split; test with representative data (images/tables) because visual pagination often differs from row counts. If browser print support is required and you need total pages, server-side PDF or a paged-media library is the most reliable option.

Recommended Answers

All 3 Replies

how do you mean?
you want to number each php-script you have? or do you have an output (like a forum, onlineshop etc) that you want to chunk up.

1) numbering you php-files: do it with en external text-file. write the name of the file and add a number:

index.php|1
main.php|2

You can then get the name of the php-script with

$PHP_SELF

and figure out the page-number from your textfile. That helps you to reorganize you project when adding or removing files from it.

2) splitting huge pages up:
When using a DB it is simple. First, get the number of rows:

SELECT COUNT(`ID`) FROM ...

. You can then restrict the output from MySQL for instance with

LIMIT 0,9

. That gives you the first 10 entries from you query. On page two you use

LIMIT 10,19

for the next ten entries and so on.
Using a textfile-system it is a bit fuzzier. Write similar functions like getallentries, getlimitedentries, and so on to keep you code tidy.

herm... its different sDjh,

i create a report.. this report are in php. it is created from combination of many different file. meaning.. at one main file, i just use @include to combine all other files..

some of this include file are shown data from databse. so, how to get a Sequence no for the page number..

please help

I hope I got you this time.

You have an index-file with a couple of includes

include("./report1/1.php");  //Page 
include("./report1/2.php");  //Page 2

and you want each page to have a unique ID at the bottom.
Do you know where the page ends or do you want to find out?

If you know, then you can just insert a running number.

$nb=1;
include("./report1/1.php");  //Page 
$nb++;
include("./report1/2.php");  //Page 2

If you have to find it out, than it shouldt be possible with CSS. I can't tell you exactly how (im not fluent to CSS) but I would start with something like:

<html>
<head>
<link type=stylesheet href="style.php?id=report1">

and then generate in style.php dynamic CSS-Script that numbers you pages.
But for CSS I guess you better ask in the "Web Design" Forum.

Regards.
Simon

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.