variable, search and display

They have: 18 posts

Joined: Feb 2005

need some direction, searching a file, each line is seperate in a stored text file.
Using a variable in the address: db_id=1392
http://domain.com/cgi-bin/cs/cs.cgi?db_id=1392

Display select text from this file:
/home/2015/public_html/cgi-bin/data/As.data

As.data file contains:
1392|macdonald|01/15/2005|Gerry M|Private Seller|FOR SALE:|1997 Ford Mustang|Red with black interior

example url:
http://domain.com/cgi-bin/cs/cs.cgi?db_id=1392

example HTML on page:
1997 Ford Mustang - Private Seller

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

Does this have to be a .cgi script? I can give you the code to do this with PHP. Perl I would have to look up as I haven't used it since I learned PHP.

-Greg

They have: 18 posts

Joined: Feb 2005

Hello

Im not sure which language Im suppose to be using fo this idea.

the template file for this has other code surrounded by "%%"
example:
%%title%%

My failed attempt to write something just shows the code entirely:

#!/usr/bin/perl

use CGI ':standard';

my $db_id = param('db_id');

$database="/home/2015/public_html/cgi-bin/data/As.data";

open (ORGDB,"<$database");
@ODB=;
close (ORGDB);
@SODB=sort(@ODB); #sort in order by ID number.

print "Content-type: text/html\n\n";
print qq~

~;

$title = "No Entries Found";

foreach $rec (@SODB){
chomp($rec);
($id,$lastname,$date,$name,$seller,$caption,$car,$color)=split(/\|/,$rec);

if($db_id eq $id){
$title = "$seller - $car";
}

print qq~

$title
~; %%TITLE%%

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.