Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating static pages from mysql db with index(s)

Status
Not open for further replies.

skydesigns

Technical User
Oct 22, 2001
4
US
Hello!

I'm working on a script for creating static html pages from a mysql db. I have a working version that creates a separate page for each record and one index file, which contains chosen fields from each record and a link to the detail page for each record.

The problem is that my db is quite large, and I would like to have multiple index pages with say - 50 links per page. I'm fairly new at Perl and can't figure our how to do this.
I would appreciate any ideas!

Here's my working script so far (excluding variables, etc.):

&connectdb;

open (TEMPL, $templ);
undef ($/);
$template=<TEMPL>;
close TEMPL;

open (TEMPL, $index_templ);
undef ($/);
$index_template=<TEMPL>;
close TEMPL;
($top, $record, $bottom)=split(/<!--record-->/, $index_template);

mkdir ($dir, 0777);
chmod($dir, 0777);
$index_file=&quot;$dir/$index_file&quot;;
$index_text_page=$top;


while ($h = $sth->fetchrow_hashref) {
%item = %{$h};

# Here we create the detail pages for each record

$line=$template;
$line=~s/\{\{([^\}]+)\}\}/$item{$1}/g;
$file=&quot;$dir/$item{login}.shtml&quot;;

open(FILE, &quot;>$file&quot;);
chmod ($file, 0666);
print FILE $line;
close FILE;

# Here we create the index page for all records - I would like to make multiple indexes, with 50 or so records per index page

$link=&quot;$item{login}.shtml&quot;;
$line=$record;
$line=~s/!link!/$link/;
$line=~s/\{\{([^\}]+)\}\}/$item{$1}/g;
$index_text_page.=$line;
}

$index_text_page.=$bottom;

open(FILE, &quot;>$index_file&quot;);
chmod ($index_file, 0666);
print FILE $index_text_page;
close FILE;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top