Someone please help/give advice?

Hi all,

Am working in a law firm and sometimes, we need to prepare content pages with hundreds of pages of documents. As such, the moment you make one changes, you literally have to go through the whole list just to change the page number, manually.

The problem is, the pages will normally be labelled e.g. ‘1-3’, ‘4-7’ etc. so it is quite impossible even to use Excel to automatically add e.g. 1 more page to them.

I’ve tried to write a script to help solve this problem (more of as practice on a super beginners level) but I’ve more or less just put together some codes here and there that I found on the net but obviously it is not working.

Could someone please help. Basically if I have a table with docs:
Doc 1 | 1 - 3
Doc 2 | 4 - 8
Dcc 3 | 9 - 12

And I want to insert another document between Doc 2 and 3, I want to be able to change it them to
Doc 1 | 1 - 3
Doc 2 | 4 - 8
NEW Doc | 9 - 10
Doc 3 | 11 - 14

So in such a scenario I’d probably just want to start changing the numbers from Doc 3 onwards by adding 2.

This is the frankenstein script that I’ve attempted:

[php]<?php
//Getting values from form
$_GET[“numbers”];
$_GET[“value”];

//Breaking data into arrays
$data = explode("-", $_POST[‘numbers’]);
$data = explode("\n", $_POST[‘numbers’]);

$arr = array ($data);
foreach ($arr as &$pages) {
$pages = $pages + $value;
}

//Table Start
print “

”;

//printing alternate values

for($i=0;$i<=count($arr);$i++)
{
if($i % 2)
{
print “$pages.

”;
}
else{
// ODD
print “$pages.-”;
}
}

//Table End
print “

”;

?>[/php]

Advice will be much appreciated!

Hoi Jos,

can you elaborate on your datastructure? What do you have per document? Do you use a database?
If forinstance per document you know the length ( or startpage-endpage, which can be used to calculate the length ) it’s just a matter of keeping a sum total of the lengths of all documents you show.

Example:
[php]
$sumLength = 0;
// Here a mechanism that loops through all documents in the list and pulls
// up the data per document.
// You’ll need $documentStarpage, $documentEndpage, $documentContent

{ $documentLength = $documentEndpage - $documentStartpage + 1; // 1-3 is 3 pages, not two.

$startPagenr = $sumLength+ 1;
$endPagenr = $sumLength+ $documentLength; 

$sumLength += $documentLength;

echo $documentContent. "<br/>\n";
echo "$startPagenr - $endPagenr<br/>\n";

}
[/php]

Is that what you meant?
Good luck.

O.

Sponsor our Newsletter | Privacy Policy | Terms of Service