Looking For Script

admin

Administrator
Staff member
I'm searching for a simple script (perl preferably, but JavaScript or PHP<br />will do) that will accomplish this scenario:<br /><br />I have a Web page with Link One and Link Two.<br /><br />I also have a flat-file database with information like<br />"link1,fruit,apple,green" and "link2,vegetable,carrot,orange"<br /><br />I would like a visitor to be able to click Link One and see a new page open<br />containing a six-cell table that has "fruit" in cell two, "apple" in cell<br />four, and "green" in cell six.<br /><br />Does anyone know where I could find such a script? I've searched<br />HotScripts.com but to no avail. They have thousands of scripts but I don't<br />even know under which classification I would find something like this, or<br />what it would be called. Any help would be appreciated. Thanks!<!--content-->
From your description, I'd say you need to create a custom script for what you want.<br />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.<br /><br />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:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br />  $db = mysql_connect("localhost", "dbusername", "dbpassword") or die ("Unable to connect to database.");<br />  mysql_select_db("dbname, $db) or die ("Unable to select database: ".mysql_error());<br /><br />  $query = "SELECT * FROM table_name";<br />  $result = mysql_query($query, $db) or die("Error while querying the database: " . mysql_error());    <br /><br />  $count = mysql_num_rows($result);<br />  echo "<table>";<br />  for ($i = 0; $i < $count; $i++)<br />  {<br />     echo "<tr>";<br />     $row = mysql_fetch_array($result);<br />     // $row is now an array containing the following fields: { link1 , fruit, apple, green }<br />     echo "<td>&nbsp;</td>";<br />     echo "<td>$row[1]</td>; // $row[1] corresponds to "fruit"<br />     echo "</tr>";<br />  }<br />  echo "</table>";<br />?><!--c2--></div><!--ec2--><br /><br />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:<br /><br />link1,fruit,apple,green<br />link2,vegetable,carrot,orange<br />link3,fruit,banana,yellow<br /><br />Or are you using a flat-file database engine, like SQLite?<!--content-->
<!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->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?<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />Yes, it will be plain text file.<!--content-->
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 '!'<br /><br />Thus your records would look like:<br /><br />link1|fruit!apple!green<br />link2|vegetable!carrot!orange<br />link3|fruit!banana!yellow<br /><br />Then we read each record into an array:<br /><br />$field[0] = "link1"<br />$field[1] = "fruit!apple!green"<br /><br />then split the sub-fields from $field[1]:<br /><br />$subfield[1] = "fruit"<br />$subfield[2] = "apple"<br />$subfield[1] = "green"<br /><br />and then commence the printout to screen<br /><br />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.<br /><br />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.<br /><br />Email is <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e --><br /><br />Regards<br /><br />Alan<!--content-->
<!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->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.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />Thanks for your kind offer, Alan. I did some further Web searching after my<br />initial post and found exactly what I was looking for. It's a perl script<br />called CSVread and yes, it uses a pipe delimited database. It's very<br />versatile and was fairly easy to set up. I've been using it for a few days<br />now and am quite satisfied. Thanks to all who responded!<!--content-->
Dear Editor,<br /><br />Glad to see you got it working.<br /><br />Sign me,<br /><br />Elated<br /><br /><br />My first letter to the editor <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /><!--content-->
 
Back
Top