Gossamer Forum
Home : Products : DBMan : Discussions :

Creating CGI script that calls certain DB fields

Quote Reply
Creating CGI script that calls certain DB fields
OK, i got the idea of creating an individual cgi script that would work alot like the random record mod for dbman, but instead of printing the random record, i would like it to spit out only the first line of the database.

here is the code for the random record script

Code:

#!/usr/bin/perl
#################################
# RandomRecord.cgi by Miles Burke (miles@scoopnewmedia.com)
# Much of this code taken from:
# Random Quotes v1.0 by John McAllister (john@highlandmedia.net)
#
# Taken from original script headers:
# Feel free to do whatever you want with this script. All I ask is
# that you do not sell it to anyone. Oh, and keeping this notice in
# the script would be kinda cool to. Have Fun! (C) 1999 - Highland Media
#
# Added by Miles: This script has been edited for use with Gossamer
# Threads excellent 'DBMan' database manager, found at:
# http://www.gossamer-threads.com/scripts/dbman/ Please note that
# 'dbman' is NOT freeware, it is shareware. Please feel free to edit and
# distribute this script, as long as this header remains intact, and that
# you dont charge for it. Thanks to John McAllister for alot of this code.
#
# If you have any questions or problems using this script, please
# post your message on the Gossamer Threads Support Forum, at:
# http://www.gossamer-threads.com/scripts/forum/
#
# Instructions:
#
# Ensure the first line points to your copy of Perl
# Make sure you set permissions right 'Chmod 755'
# Copy and Paste the 2 variables required from your .cfg file
# Edit the 'display' section below, ensuring that you:
# use $dbman_field[X] where X is the number found in the
# 'Database Definition' section of your .cfg file. (ie: to show
# the region entry, look up your .cfg file
# 'region' => [6, 'alpha', 20, 50, 0, '', '' ], and then add
# $dbman_field[6] whereever you wish it to appear in your page.
# Always ensure you have the print " and "; at front and end of lines.
#
# Now call it with <!--#exec cgi="/cgi-bin/RandomRecord.cgi"-->
################################
# These 2 variables should match *exactly* what your .cfg file says...
# URL of the directory dbman resides in. No Trailing Slash Please.
$db_dir_url = "http://www.biafore.com";
# URL of dbman.
$db_script_url = $db_dir_url . "/contact.cgi";
# This one is *not* the same as .cfg file:
# Full Path and File name of the database file
$db_file = "/home/biafo50/public_html/contact.db";

##################################
print "Content-type: text/html\n\n";
open (DATABASE, "<$db_file") || die print "Eek! Couldn't open database!";
@line=<DATABASE>;
close (DATABASE);
srand;
$array = $line[int rand(@line)];
# If you're $db_delim is not '|', change it here (between /\ and /,)
@dbman_field = split (/\|/, $array);
# Display Section:
print "$dbman_field[2]";
;


i figured the srand; command should be changed and also the [int rand@line)];

I am just not sure what exactly i need to do just to just print the first line

Thanks in advance
Jose
Subject Author Views Date
Post Creating CGI script that calls certain DB fields TKEP1008 2382 Jul 14, 2004, 11:05 PM