CSVread

CSVread - Read a database and display the results in a webpage

Read, search and display information from a CSV database on your website. Plugs directly into your site look and feel with little effort. Automatically filter the information displayed. (CGI/Perl)

Requirements

Files you will need to download:

  • CSVread script
  • HTML Template to show results
  • CSV Database

Download Script & example files:

Things you have to do:

  • Download the script and make a few changes
  • Create a link on your webpage
  • Create database (or let CSVwrite do it!)
  • Create a 'template' in your own style
  • Upload the script, template and database.

Minimum Requirements:

  • A little experience in uploading and running CGI Perl scripts
  • Your own website with FTP access
  • Permission to run CGI scripts on your server
  • UNIX web hosting with the current version of Perl
Setting-up the script

You will need to make some small changes to customise the script to make it work on your website. Open and edit the script in notepad or notepad++

#!/usr/bin/perl (This is your 'path to perl')
##########################################################
my $CSV_file = "database.csv"; (This is the PATH of your database)
my $HTML_template = "template.htm"; (This is the PATH to your template)
my $no_matches_found = "Sorry, no results found"; (Message if no results found)
my $display_order = 1; (Order the results page, 1 newest first 0 oldest first)
##########################################################

Upload to your website and CHMOD 755 if in the public directory or 777 if hidden

Create your database

The database is a CSV database, CSV stands for 'character separated values' sometimes called a flatfile database. It is basically a text file and the character | serperates the data.

When you download the scripts a demo database is included, you can edit this online with CSVedit or on your computer with Excel. However the best way to create the database is when you run CSVwrite the first time as it will create the database for you, make sure you put some data in each field of the form.

If you do create your own, don't use any special characters or spaces in the field names. Keep them short as your browser can only send a limited number of characters to the database at any one time. Ensure they match your form fields exactly. The size limitations of your database are determined by your web hosting and the server specifications.

Example database: The first line is the heading and the rest the data. You can have as many field names as you like in the database. The field names must exacly match the fields in your form.

fieldname1|fieldname2|fieldname3|fieldname4
This is a text box|yes|1|Drop it A
This is a text box|Yes|2|Drop it B
This is a text box|Yes|3|Drop it C

Your database should be less than 1000 records and under 1MB run smoothly on most shared web servers.

Please do not use field names in your database used in the script or template. The following are used by the scripts and can not be used as field names: name, method, action, page, record, header, display, search.

Upload to your website and CHMOD 755 if in the public directory or 777 if hidden

Create your HTML template

This will display the results in the way you wish to see them. Using any HTML web style you like. Create a simple template first, and save it as template.htm Everything inside the template brackets is repeated for each record (including any HTML code), everything outside the template brackets is displayed just once (you may wish to display a menu). A sample template is included in the download.

Make sure the fields have the same name as the database fields, insert the fields you wish to display in any format you like with the field names inside double brackets [[fieldname]]

Example code:

<html>
<head>
<title>Page Title</title>
</head>
<body>
<br>
<!-- "start template" -->
<template>
<b>Field 1</b> [[field1]]<br>
<b>Field 2</b> [[field2]]<br>
<b>Field 3</b> [[field3]]<br>
<b>Field 4</b> [[field4]]<br>
<b>Field 5</b> [[field5]]<br>
<br>
</template>
<!-- "end template" -->
<b>Total number of records:</b> [[#_total]] <b>Matching records:</b> [[#_matches]]
</body>
</html>

With CSVread you can display the total number of records, and the number of matching records. Insert the code below anywhere you like on the template page, outside the template brackets.

Total number of records:</b> [[#_total]] <b>Matching records:</b>* [[#_matches]]

The script will read and display the code from your template. You can not include any SSI (Server side includes) in the template. This is not possible with CGI Perl scripts.

Reset the demo database

The live demo allows you to post data, add, edit and delete fields or records.
Click to reset the demo database back to default.