editor Posted August 2, 2004 Posted August 2, 2004 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! Quote
borfast Posted August 2, 2004 Posted August 2, 2004 (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 August 2, 2004 by TCH-Raul Quote
editor Posted August 2, 2004 Author Posted August 2, 2004 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. Quote
newhorizonz Posted August 4, 2004 Posted August 4, 2004 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 Quote
editor Posted August 11, 2004 Author Posted August 11, 2004 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! Quote
TCH-Rob Posted August 11, 2004 Posted August 11, 2004 Dear Editor, Glad to see you got it working. Sign me, Elated My first letter to the editor Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.