Jump to content

Recommended Posts

Posted

I'm searching for a simple script (perl preferably, but JavaScript or PHP

will do) that will accomplish this scenario:

 

I have a Web page with Link One and Link Two.

 

I also have a flat-file database with information like

"link1,fruit,apple,green" and "link2,vegetable,carrot,orange"

 

I would like a visitor to be able to click Link One and see a new page open

containing a six-cell table that has "fruit" in cell two, "apple" in cell

four, and "green" in cell six.

 

Does anyone know where I could find such a script? I've searched

HotScripts.com but to no avail. They have thousands of scripts but I don't

even know under which classification I would find something like this, or

what it would be called. Any help would be appreciated. Thanks!

Posted (edited)

From your description, I'd say you need to create a custom script for what you want.

I'd suggest Hotscripts.com under the "Database tools" category but what you want is such a specific thing, that I don't think you'll find anything there.

 

You basically want a script that fetches information from that flat-file database and outputs it in an HTML table. I don't know which database file format you're using but here's an example script in PHP using a MySQL database:

><?php
 $db = mysql_connect("localhost", "dbusername", "dbpassword") or die ("Unable to connect to database.");
 mysql_select_db("dbname, $db) or die ("Unable to select database: ".mysql_error());

 $query = "SELECT * FROM table_name";
 $result = mysql_query($query, $db) or die("Error while querying the database: " . mysql_error());	

 $count = mysql_num_rows($result);
 echo "<table>";
 for ($i = 0; $i < $count; $i++)
 {
    echo "<tr>";
    $row = mysql_fetch_array($result);
    // $row is now an array containing the following fields: { link1 , fruit, apple, green }
    echo "<td> </td>";
    echo "<td>$row[1]</td>; // $row[1] corresponds to "fruit"
    echo "</tr>";
 }
 echo "</table>";
?>

 

Edit: I just thought of something: is your flat-file database exactly the way you described it? I mean, is it a simple text file with one row of information per line? Like so:

 

link1,fruit,apple,green

link2,vegetable,carrot,orange

link3,fruit,banana,yellow

 

Or are you using a flat-file database engine, like SQLite?

Edited by TCH-Raul
Posted
is your flat-file database exactly the way you described it? I mean, is it a simple text file with one row of information per line?

 

Yes, it will be plain text file.

Posted

We have been using our own custom-built script to do exactly what you describe for some time now! What we tend to do however is to separate fields with the pipe '|' delimiter and the sub-fields with an exclaimation '!'

 

Thus your records would look like:

 

link1|fruit!apple!green

link2|vegetable!carrot!orange

link3|fruit!banana!yellow

 

Then we read each record into an array:

 

$field[0] = "link1"

$field[1] = "fruit!apple!green"

 

then split the sub-fields from $field[1]:

 

$subfield[1] = "fruit"

$subfield[2] = "apple"

$subfield[1] = "green"

 

and then commence the printout to screen

 

Do you create the flat-file manually or via another perl script? If by a script you will need to change the method used to write the record to file replacing the commas with pipe or exclaimation.

 

If you would like to send over the files / and any programs used to write the file (if any) then I will make the amendments and create an output script in perl for you. Also it would be a good idea to send a link to the site and a copy of the html pages to be be used for output so that I can adjust the perl output accordingly.

 

Email is admin@newhorizonz.net

 

Regards

 

Alan

Posted
If you would like to send over the files / and any programs used to write the file (if any) then I will make the amendments and create an output script in perl for you.

 

Thanks for your kind offer, Alan. I did some further Web searching after my

initial post and found exactly what I was looking for. It's a perl script

called CSVread and yes, it uses a pipe delimited database. It's very

versatile and was fairly easy to set up. I've been using it for a few days

now and am quite satisfied. Thanks to all who responded!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...