Gossamer Forum
Home : General : Perl Programming :

Returning customised html display pages of search results

Quote Reply
Returning customised html display pages of search results
Hi

I have a search script which takes info from a flat file database and displays it in a basic html layout, but I want results displayed within a customised page like the ones on this web site.

EXAMPLE OF WHAT I'M LOOKING FOR:

<TABLE cellspacing="2" cellpadding="2" border="0">

<TR>

<TD align="center" width="200"><B>Name</B></TD>

<TD align="center" width="200"><B>Address</B></TD>

<TD align="center" width="200"><B>Tel No.</B></TD>

</TR>

<TR>

<TD align="center" width="200"><B>Name Variable</B></TD>

<TD align="center" width="200"><B>Address Variable</B></TD>

<TD align="center" width="200"><B>Tel No. Variable</B></TD>

</TR>

</TABLE>

It would be even better if there were "Next " and "Previous" buttons with only 10 results dosplayed at a time.

Can anyone help?
Quote Reply
Re: Returning customised html display pages of search results In reply to
Just making a guess since I have no clue how your db works.
Code:
open(DB,"/path/to/db") | | die "Can't open db";
@db = (<DB> );
close (DB);

$count = 0;
$newcount = 0;
foreach $line (@db) {
$newcount++;
$count++;
if ($in{'count'}) {
unless ($in{'count'} < $count) {
$newcount = 0;
next;
}
}
chomp $line;
@record = split(/\|/,$line);
until ($newcount == 10) {
push(@set,@record);
next;
}
}

return @set;

This is just taking out the records in order and displaying them 10 at a time. This is assuming that you are using a pipe as a delimeter. Here is the html to display your variables. This can go in another sub.
Code:
print "Content-type: text/html\n\n";
$back = ($in{'count'} - 10);
print qq|<a href="http://www.yourserver.com/cgi-bin/thisscript.cgi?count=$back"><<Previous</a>     <a href="http://www.yourserver.com/cgi-bin/thisscript.cgi?count=$in{'count'}">Next>></a>|;
foreach $recordset (@set) {
print qq|
<TABLE cellspacing="2" cellpadding="2" border="0">

<TR>

<TD align="center" width="200"><B>Name</B></TD>

<TD align="center" width="200"><B>Address</B></TD>

<TD align="center" width="200"><B>Tel No.</B></TD>

</TR>

<TR>

<TD align="center" width="200"><B>$record[0]</B></TD>

<TD align="center" width="200"><B>$record[1]</B></TD>

<TD align="center" width="200"><B>$record[2]</B></TD>

</TR>

</TABLE>|;
}

Hope this fits in to what you are doing. It's pretty late, and I'm tired, so I wouldn't be surprised if it doesn't work. I'll check on you tomorrow.

PS: Don't forget to take out the space between the | |.

Chris Ellenburg
chris@wfmy.com

------------------
WFMY-TV Webmaster

[This message has been edited by Chris071371 (edited November 23, 1999).]

[This message has been edited by Chris071371 (edited November 23, 1999).]