473,383 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to populate HTML table from local text file.

Hi,

I am looking for a way to populate an HTML table from an external
local text file which looks like this:

DATE/TIME LAT. LON. DEPTH. ML.
-------------------- ---------- ---------- ------- -------
21/03/2005-04:06:03 XX,XX XX,XX 171 3,42
21/03/2005-12:23:53 XX,XX XX,XX 500 5,4
21/03/2005-12:43:10 XX,XX XX,XX 553 5,38
21/03/2005-18:47:51 XX,XX XX,XX 162 3,91
21/03/2005-19:29:49 XX,XX XX,XX 500 3,51
21/03/2005-20:04:51 XX,XX X,X 75 3,72

The file could have more rows (DATA) that I show here. The file is
provided to me on a daily basis and I have to update a web page daily
with the contents of the file.

I considered using JavaScript embedded in the HTML page but I am a
newbie on what scripting for the web it refers.

How can I populate the HTML table with this text file which changes
everyday.

Also, is it possible to use php client-side only, without a server?

Your help, suggestions and feedback questions will be much
appreciated.

Thanks.

Alex.
Jul 23 '05 #1
11 24538
alex (al**************@hotmail.com) wrote:
: Hi,

: I am looking for a way to populate an HTML table from an external
: local text file which looks like this:

: DATE/TIME LAT. LON. DEPTH. ML.
: -------------------- ---------- ---------- ------- -------
: 21/03/2005-04:06:03 XX,XX XX,XX 171 3,42
: 21/03/2005-12:23:53 XX,XX XX,XX 500 5,4
: 21/03/2005-12:43:10 XX,XX XX,XX 553 5,38
: 21/03/2005-18:47:51 XX,XX XX,XX 162 3,91
: 21/03/2005-19:29:49 XX,XX XX,XX 500 3,51
: 21/03/2005-20:04:51 XX,XX X,X 75 3,72

the absolutely easiest way is to simply wrap the above text with the <pre>
</pre> tags.

<html>
<head> <title> data from 21/03/2005 </title> </head>
<body>
<pre>
DATE/TIME LAT. LON. DEPTH. ML.
-------------------- ---------- ---------- ------- -------
21/03/2005-04:06:03 XX,XX XX,XX 171 3,42
21/03/2005-12:23:53 XX,XX XX,XX 500 5,4
</pre>
</body>
</html>

--

This space not for rent.
Jul 23 '05 #2
alex wrote:

I am looking for a way to populate an HTML table from an external
local text file which looks like this: 21/03/2005-04:06:03 XX,XX XX,XX 171 3,42
It is probably possible, using XmlHttpRequest, but a fair bit of work,
limited browser support, and not very accessible. Far better to generate
the HTML before it reaches the client.
Also, is it possible to use php client-side only, without a server?


Yes ... but not on the web.

If you can't run any form of scripting on your server, then your best bet
would be to look at running it on another machine (such as your
workstation) and uploading the output to your webserver.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #3
Carved in mystic runes upon the very living rock, the last words of alex
<al**************@hotmail.com> of comp.lang.javascript make plain:
I am looking for a way to populate an HTML table from an external
local text file which looks like this:

How can I populate the HTML table with this text file which changes
everyday.

Also, is it possible to use php client-side only, without a server?


Yes and no. No, you can't run PHP locally and have it integrate with
pages served to your browser from somewhere else. Yes, you can install a
web server such as Apache on your local machine and have it serve pages
to you locally, integrating with PHP as desired. This is most likely what
I would do if my production server didn't have PHP (well, actually I
would get a different provider in that case); install Apache and PHP
locally, write a PHP script to read the file and generate the output,
upload static content to production server.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Jul 23 '05 #4
"Malcolm Dew-Jones" <yf***@vtn1.victoria.tc.ca> wrote in message
news:42******@news.victoria.tc.ca...
alex (al**************@hotmail.com) wrote:
: Hi,

: I am looking for a way to populate an HTML table from an external
: local text file which looks like this:

: DATE/TIME LAT. LON. DEPTH. ML.
: -------------------- ---------- ---------- ------- -------
: 21/03/2005-04:06:03 XX,XX XX,XX 171 3,42
: 21/03/2005-12:23:53 XX,XX XX,XX 500 5,4
: 21/03/2005-12:43:10 XX,XX XX,XX 553 5,38
: 21/03/2005-18:47:51 XX,XX XX,XX 162 3,91
: 21/03/2005-19:29:49 XX,XX XX,XX 500 3,51
: 21/03/2005-20:04:51 XX,XX X,X 75 3,72

the absolutely easiest way is to simply wrap the above text with the <pre>
</pre> tags.


I like Malcom's solution for its ease.

Or do you *need* the data in a table for some reason?

Perhaps to right-align numbers or hyperlink cells?
Also, I'm not familiar with Lat/Lon presented as "XX,XX";

Per http://jan.ucc.nau.edu/~cvm/latlongdist.html

Valid formats for Latitudes and Longitudes are:

option 1: dddmmssD or ddd mm'ss" D

where ddd = 1-3 digits for degrees, mm = 2 digits for minutes, ss = 2 digits
for seconds and D = N,S,E, or W. The seconds and special characters (spaces,
apostrophes, quotes) are all optional in this format. This leads to quite a
large number of possible valid formats.

option 2: ddd.ffffD

where ddd = 0-3 digits, ffff = 0-10 digits and D = N,S,E, or W. This format
represents a decimal number of degrees. If the number of degrees is a whole
number, the decimal point is optional.

option3: ddd mm.ffff'D

where ddd = 0-3 digits for degrees, mm = 2 digits for minutes, ffff = 0-10
digits for decimal portion of minutes and D = N,S,E, or W. This format
represents degrees and a decimal number of minutes.
Jul 23 '05 #5
alex wrote:
Hi,

I am looking for a way to populate an HTML table from an external
local text file which looks like this:

DATE/TIME LAT. LON. DEPTH. ML.
-------------------- ---------- ---------- ------- -------
21/03/2005-04:06:03 XX,XX XX,XX 171 3,42
21/03/2005-12:23:53 XX,XX XX,XX 500 5,4
21/03/2005-12:43:10 XX,XX XX,XX 553 5,38
21/03/2005-18:47:51 XX,XX XX,XX 162 3,91
21/03/2005-19:29:49 XX,XX XX,XX 500 3,51
21/03/2005-20:04:51 XX,XX X,X 75 3,72

The file could have more rows (DATA) that I show here. The file is
provided to me on a daily basis and I have to update a web page daily
with the contents of the file.

I considered using JavaScript embedded in the HTML page but I am a
newbie on what scripting for the web it refers.

<div id="foo"><--INCLUDE FILE HERE--></div>
<script type="text/JavaScript">
onload= function(){
var d=document.getElementById("foo").innerHTML.split(/\s+/)
document.getElementById("foo").innerHTML=table_mak er(5,d);
}
function table_maker(columns,array){
var txt="<TABLE cellpadding=1 cellspacing=1 border=1>"
var rows=Math.ceil(array.length/columns);
for(var r=0,t=0;r<rows;r++){
txt+="<TR>"
for(var c=0;c<columns;c++){
txt+="<TD>"+array[t++]+"</TD>"
}
txt+="</TR>"
}
txt+="</TR></TABLE>"
return txt;
}
</script>

Mick
Jul 23 '05 #6
"McKirahan" <Ne**@McKirahan.com> wrote in message news:<W7********************@comcast.com>...
"Malcolm Dew-Jones" <yf***@vtn1.victoria.tc.ca> wrote in message
news:42******@news.victoria.tc.ca...
alex (al**************@hotmail.com) wrote:
: Hi,

: I am looking for a way to populate an HTML table from an external
: local text file which looks like this:

: DATE/TIME LAT. LON. DEPTH. ML.
: -------------------- ---------- ---------- ------- -------
: 21/03/2005-04:06:03 XX,XX XX,XX 171 3,42
: 21/03/2005-12:23:53 XX,XX XX,XX 500 5,4
: 21/03/2005-12:43:10 XX,XX XX,XX 553 5,38
: 21/03/2005-18:47:51 XX,XX XX,XX 162 3,91
: 21/03/2005-19:29:49 XX,XX XX,XX 500 3,51
: 21/03/2005-20:04:51 XX,XX X,X 75 3,72

Or do you *need* the data in a table for some reason?


Thanks for your answer, McKirahan. Just as a follow-up to some
questions...
I do need the data in a table in order to hyperlink some cells.
Also, I'm not familiar with Lat/Lon presented as "XX,XX";
Sorry, I only made a representation of Lat/Lon in order not to reveal
actual values of Lat/Lon that correspond to data in my organization.
The values for Lat/Lon given to me are according to option 2 below,
decimal number of degrees. Thanks for the good input.
Per http://jan.ucc.nau.edu/~cvm/latlongdist.html

option 2: ddd.ffffD

where ddd = 0-3 digits, ffff = 0-10 digits and D = N,S,E, or W. This format
represents a decimal number of degrees. If the number of degrees is a whole
number, the decimal point is optional.

Jul 23 '05 #7
McKirahan wrote:
[...]

Also, I'm not familiar with Lat/Lon presented as "XX,XX";

Per http://jan.ucc.nau.edu/~cvm/latlongdist.html

Valid formats for Latitudes and Longitudes are:

[...]

Whilst your reference to the Northern Arizona University may have
appropriate formats for the OP's purposes, the international standard
is ISO 6709:1983.

There are 2 main difference between ISO and your quoted source;

1. Hemispheres are denoted by "-" for W and S and "+" for E and N. I
suppose the mathematical symbols are more widely understood than
letters from the English alphabet.

2. The ISO formats are unambiguous.

A free version of the standard can be found here:

<URL:http://en.wikipedia.org/wiki/ISO_6709>

Though to ensure full compliance (if required), a copy should be
purchased from ISO.

--
Rob
Jul 23 '05 #8
Mick White <mw***********@rochester.rr.com> wrote in message news:<b%********************@twister.nyroc.rr.com> ...
alex wrote:
Hi,

I am looking for a way to populate an HTML table from an external
local text file which looks like this:

DATE/TIME LAT. LON. DEPTH. ML.
-------------------- ---------- ---------- ------- -------
21/03/2005-04:06:03 XX,XX XX,XX 171 3,42
21/03/2005-12:23:53 XX,XX XX,XX 500 5,4
21/03/2005-12:43:10 XX,XX XX,XX 553 5,38
21/03/2005-18:47:51 XX,XX XX,XX 162 3,91
21/03/2005-19:29:49 XX,XX XX,XX 500 3,51
21/03/2005-20:04:51 XX,XX X,X 75 3,72

The file could have more rows (DATA) that I show here. The file is
provided to me on a daily basis and I have to update a web page daily
with the contents of the file.

I considered using JavaScript embedded in the HTML page but I am a
newbie on what scripting for the web it refers.
<div id="foo"><--INCLUDE FILE HERE--></div>


Forgive my ignorance, but, how do i include the file as dictated right
above?
Is there some kind of HTML statement that allows you to include an
external text file ? Please clarify as am a newbie on this. Thanks
Mick.

Alex.
<script type="text/JavaScript">
onload= function(){
var d=document.getElementById("foo").innerHTML.split(/\s+/)
document.getElementById("foo").innerHTML=table_mak er(5,d);
}

[...]
Jul 23 '05 #9
On 26 Mar 2005 21:13:39 -0800, in comp.lang.javascript
al**************@hotmail.com (alex) wrote:
| Hi,
|
| I am looking for a way to populate an HTML table from an external
| local text file which looks like this:
|
| DATE/TIME LAT. LON. DEPTH. ML.
| -------------------- ---------- ---------- ------- -------
| 21/03/2005-04:06:03 XX,XX XX,XX 171 3,42
| 21/03/2005-12:23:53 XX,XX XX,XX 500 5,4
| 21/03/2005-12:43:10 XX,XX XX,XX 553 5,38
| 21/03/2005-18:47:51 XX,XX XX,XX 162 3,91
| 21/03/2005-19:29:49 XX,XX XX,XX 500 3,51
| 21/03/2005-20:04:51 XX,XX X,X 75 3,72
|
| The file could have more rows (DATA) that I show here. The file is
| provided to me on a daily basis and I have to update a web page daily
| with the contents of the file.
|
| I considered using JavaScript embedded in the HTML page but I am a
| newbie on what scripting for the web it refers.
|
| How can I populate the HTML table with this text file which changes
| everyday.
|
| Also, is it possible to use php client-side only, without a server?
|
| Your help, suggestions and feedback questions will be much
| appreciated.


You could use javascript to open and read the file. If the user has
javascript disabled then they will see nothing.

Alternatively you could use an IFrame on your page to display your
file.

If the file extension is txt then browsers will display the text as it
appears in the file - no formatting.

If the file extension is csv then Internet Explorer will reformat the
text and display it in a limited Excel spreadsheet layout. Other
browsers (Firefox) will just show the text.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>External text file</title>
</head>

<body>
<P>this is some text, menus etc</P>
<iframe src="pc-full.csv" width="100%" frameborder="1"
scrolling="auto" height="350px"></iframe>
</body>
</html>
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Jul 23 '05 #10
alex wrote:
Mick White <mw***********@rochester.rr.com> wrote in message news:<b%********************@twister.nyroc.rr.com> ... [...]

<div id="foo"><--INCLUDE FILE HERE--></div>

Forgive my ignorance, but, how do i include the file as dictated right
above?
Is there some kind of HTML statement that allows you to include an
external text file ? Please clarify as am a newbie on this. Thanks
Mick.

Alex.

Search for "SSI".

Mick

<script type="text/JavaScript">
onload= function(){
var d=document.getElementById("foo").innerHTML.split(/\s+/)
document.getElementById("foo").innerHTML=table_m aker(5,d);
}


[...]

Jul 23 '05 #11
alex wrote:
Hi,

I am looking for a way to populate an HTML table from an external
local text file which looks like this:

DATE/TIME LAT. LON. DEPTH. ML.
-------------------- ---------- ---------- ------- -------
21/03/2005-04:06:03 XX,XX XX,XX 171 3,42 21/03/2005-12:23:53 XX,XX XX,XX 500 5,4
21/03/2005-12:43:10 XX,XX XX,XX 553 5,38 21/03/2005-18:47:51 XX,XX XX,XX 162 3,91 21/03/2005-19:29:49 XX,XX XX,XX 500 3,51 21/03/2005-20:04:51 XX,XX X,X 75 3,72
The file could have more rows (DATA) that I show here. The file is
provided to me on a daily basis and I have to update a web page daily
with the contents of the file.

I considered using JavaScript embedded in the HTML page but I am a
newbie on what scripting for the web it refers.

How can I populate the HTML table with this text file which changes
everyday.

Also, is it possible to use php client-side only, without a server?

Your help, suggestions and feedback questions will be much
appreciated.

Thanks.

Alex.


Server-based preprocessors were designed for this sort of thing; any
time you attempt it at the client, you're in the wild-wild-west, so to
speak, hoping for a reasonably controlled environment (unlikely).
Nevertheless: you could simply download that text file into a hidden
iframe in the page and extract the data from there...browser support
for this - and DOM table-building - is pretty good these days. See if
this does anything. You may have to find any control characters
inserted by googlegroups and s & r them....sorry about that.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">

body {
font-size: 100%;
background: #9a9;
}
h3 {
width: 180px;
font: 18px "arial black";
color: #474;
margin: 80px auto 0 auto;
}
#stuff {
width: 600px;
margin: 10px auto;
}
#stuff th {
font: 11px "arial black";
color: #060;
letter-spacing: .4em;
border-left: 3px #000 solid;
border-right: 1px #000 solid;
background: #fff;
}
#stuff td {
font: normal 12px monospace;
text-align: center;
padding: 3px;
border-top: 1px #888 solid;
border-right: 1px #000 solid;
border-bottom: 1px #888 solid;
border-left: 3px #000 solid;
background: #d0d8d0;
}
#buffer {
display: none;
}

</style>
<script type="text/javascript">

onload = function()
{
if (!document.getElementById
|| !document.getElementsByTagName)
return;
var frm = null,
prenode,
tbod = document.getElementById('tbod'),
data = '';
if ((frm = top.frames['buffer']) //iframe
&& frm.document)
{ //get <pre> parent
prenode = frm.document.getElementsByTagName('pre').item(0);
if (null != prenode
&& null != prenode.firstChild
&& /#text/.test(prenode.firstChild.nodeName)) //text node
{
data += prenode.firstChild.data; //read
data = data.split(/[\n\r]/); //separate lines
data.splice(0, 2); //lose first two (legend)
var i = 0,
l = data.length,
rowdata,
ii, ll, tr, td;
for (; i < l; ++i)
{
tr = document.createElement('tr'); //new row
tbod.appendChild(tr);
rowdata = data[i].split(/\s{3,}/); //separate bits
for (ii = 0, ll = rowdata.length; ii < ll; ++ii)
{
td = document.createElement('td'); //new cell
td.appendChild(document.createTextNode(rowdata[ii]));
tr.appendChild(td);
}
}
}
}
}

</script>
</head>
<body>
<h3>&amp;#149; Mystery Data &amp;#149;</h3>
<table id="stuff">
<thead>
<tr>
<th>DATE/TIME</th>
<th>LAT.</th>
<th>LON.</th>
<th>DEPTH.</th>
<th>ML.</th>
</tr>
</thead>
<tbody id="tbod">
</tbody>
</table>
<iframe id="buffer" name="buffer" src="data.txt"></iframe>
</body>
</html>

Made some assumptions about the consistency of the text formatting.

Jul 23 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: alex | last post by:
Hi, I am looking for a way to populate an HTML table from an external local text file which looks like this: DATE/TIME LAT. LON. DEPTH. ML....
1
by: Ward B | last post by:
Greetings. I'm somewhat new to this whole MySQL/PHP thing and need a little help. My web hosting service uses phpMyAdmin and at the bottom of the screen iis an area where I can upload a text...
1
by: Ward B | last post by:
Greetings. I'm somewhat new to this whole MySQL/PHP thing and need a little help. My web hosting service uses phpMyAdmin and at the bottom of the screen iis an area where I can upload a text...
0
by: Bogey | last post by:
Hi, I am a complet newby in XML; I just want to create a table for datas coming from XML file <Study StudyNumber="3"> <Sample> <Destination Position="D2"/> <Source SourcePlate="P3"...
3
by: Shailesh Patel | last post by:
Hi, How do I export Html table to excel file? Thank you in advance. Shailesh
7
by: jcnone | last post by:
Does anyone know how to populate form fields on a html web page (client side) with data from an Excel file (CSV) or text file. I am currently having to input data to many text fields manually. I...
8
by: Irene | last post by:
Hi, I have an MS Access Database with 1 Table containing about 2 million records in Unicode (diferent languages). I would like to export the Table to a Text file (CSV, Tab, etc.) Access...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.