View Full Version : variable, search and display
rayzun
02-16-2005, 10:19 PM
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:
<title>1997 Ford Mustang - Private Seller
</title>
mlseim
02-16-2005, 10:52 PM
#!/usr/bin/perl
use CGI ':standard';
### Bring in variable from URL or Form.
my $db_id = param('db_id');
### Open the database text file.
$database="../data/As.data"; # you might have to play with the relative path
open (ORGDB,"<$database");
@ODB=<ORGDB>;
close (ORGDB);
@SODB=sort(@ODB); #sort in order by ID number.
### Start printing out the output to user's browser.
print "Content-type: text/html\n\n";
print qq~
<html>
<head>
~;
$title = "No Entries Found"; #default title if ID is not found.
### go through the list of entries.
foreach $rec (@SODB){
chomp($rec);
($id,$lastname,$date,$name,$seller,$caption,$car,$color)=split(/\|/,$rec);
### test to see if db_id equals $id.
if($db_id eq $id){
$title = "$seller - $car";
}
print qq~
<title>$title</title>
</head>
<body>
Your website with things to display:<br>
$id<br>
$date<br>
etc.<br>
</body>
</html>
~;
rayzun
02-17-2005, 09:49 PM
thanks for the direction..
I tried the above code and the page just shows the code entirely, with being parsed I guess.
Im still on this idea
other code found in the template txt file is shown like:
<META name="keywords" content="%%KEYWORDS%%">
so basically
http://domain.com/cgi-bin/cs/cs.cgi
is the file for all other pages
mlseim
02-17-2005, 11:08 PM
As I replied via private message,
The script I posted is a Perl script and can only
run in your cgi-bin on your web server.
You mention a file called "cs.cgi"
Are you sure you have that file installed in your cgi-bin,
and perhaps you are misunderstanding what a Perl (CGI)
script is?
Maybe your whole Perl script is put together by the
script called "cs.cgi" and it uses a bunch of template
files to display your pages?
We're going to need a bit more information on what
is installed, and a list of the files that might be involved.
.
rayzun
02-17-2005, 11:20 PM
Hello,
##
Maybe your whole Perl script is put together by the
script called "cs.cgi" and it uses a bunch of template
files to display your pages?
##
Yes, I believe you. I think the script grabs information from many different files (txt, data files etc..)
domain.com/cgi-bin/cs/cs.cgi?db=cars&search=on&db_id=1352
-
db=cars
(cars.default.txt)
is the html template text file, where I believe to include the additional script.
db_id=1352
(cars.data)
is the information file, contains all the information to fill the HTML template.
information is seperated by "|" symbol. The very first field for every new line is a number to identify the information.
taken from the cars.default.txt template:
<HTML><HEAD>
<TITLE>%%TITLE%% </TITLE>
<META name="keywords" content="%%KEYWORDS%%">
</HEAD><BODY %%COOKIE_CHECK%%>
This was a very confusing question for me to ask, any help is really going to go along way.
mlseim
02-18-2005, 01:33 AM
So you already have a Perl script that does the whole car thing.
You want to have a search function for it, and it already
doesn't have a search function?
I'm confused because it already looks like it has a search feature.
Any Perl modifications need to happen with the actual Perl script.
That script would be: "classifieds.cgi"
I'm sorry I don't understand what you're asking ...
rayzun
02-18-2005, 01:38 AM
I have re-written it to hopefully better describe the result.
as I can see, the title is pre-chosen. And not unique to the webpage contents.
would it be a better idea to place a link to or show the entire cgi script??
-
Using a variable in the URL address: db_id=1352
example url:
domain.com/cgi-bin/cs/cs.cgi?db=cars&search=on&db_id=1352
get a select set point of information and place in the title of the webpage.
in the URL: db=cars refers to this file: (cars.default.txt)
/home/2015/public_html/cgi-bin/cs/temlate/cars.default.txt
cars.default.txt is the template for cgi script.
I believe it uses many txt files to display different pages and areas of the page aswell.
example from the template (I have removed the < >):
HTML
HEAD
TITLE %%TITLE%%
/TITLE
META name=keywords content=%%KEYWORDS%%
/HEAD
BODY %%COOKIE_CHECK%%
in the URL: db_id=1352 refers to this file: (cars.data)
/home/2015/public_html/cgi-bin/cs/data/cars.data
information is seperated by "|" symbol.
The very first field for every new line is a number to identify the information.
Example of cars.data file contains:
1352|macdonald|01/15/2005|Gerry M|Private Seller|FOR SALE:|1997 Ford Mustang|black interior
1353|mac|01/13/2005|Michael|Private Seller|FOR SALE:|Ford Bronco|black
#####################
Result I would like to have happen
domain.com/cgi-bin/cs/cs.cgi?db=cars&search=on&db_id=1352
THe title would now have the
7 and 5 field displayed in the title:
1352|macdonald|01/15/2005|Gerry M|Private Seller|FOR SALE:|1997 Ford Mustang|black interior
html
head
title
1997 Ford Mustang - Private Seller
/title
/head
body etc..
mlseim
02-18-2005, 01:46 AM
All I can think of now is for you to copy the whole Perl script
to Notepad and save it as a text file. Attach that text file
to another post as an attachment. That way, we can look
at it. In order to change the title, it needs to be altered in
the Perl script ... but we can't see the script.
rayzun
02-18-2005, 01:54 AM
The cgi can be found here:
http://yothat.info/cgi.txt
mlseim
02-18-2005, 04:41 AM
Wow,
That's the most elaborate thing I've ever seen ...
There must be dozens of scripts connected together.
I don't see anything in that script that actually
displays the HTML (using a template). The spot
must be in another script, but holy cats, I don't
know how you're going to find it.
Is there any way you can contact the author,
or place that you got the script from. Maybe ask
them how to add the more descriptive <title>?
I can see this is going to be hard to figure out using
this forum.
rayzun
02-18-2005, 05:07 AM
I got this bit of code, although it is I think PHP, would this work if it could be re-written into cgi script or Perl ??
$lines = file('/cgi-bin/data/As.data');
foreach ($lines as $line) {
$parts = explode('|', $line);
if ($parts[0] == $_GET['db_id']) {
// this is the line you want
print_r($parts);
}
}
mlseim
02-18-2005, 05:25 AM
But your goal is to maintain the same script you already have,
but change the <title> line to include more information.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.