batch processing web pages

I have not used AppleScript very much at all but I think that it could really help me at the moment, My problem is this,
I have a lot of webpages that need the link to the database changed by one number and then saved with that number as part of its name. For example:

$query=“SELECT * FROM build WHERE id=‘c0259’”; << This is the number (c0259) which I want to change

And save the file as “”

The next file would be “c0260” and so forth.

I have tried to find an example but cannot find something that increments a number.
Thanks for any advice you might be able to give me. Peter

Model: PowerBook G4
AppleScript: 1.9.3
Browser: Safari 312.6
Operating System: Mac OS X (10.3.9)

Questions should be directed to AppleScript | OS X, so I’ve moved this there. Code Exchange is for sharing finished scripts.