mechanicus01
asked on
Insert Data into HTML Table from Text file
Hello
How can I add data from a .txt file to an HTML table?
I would like to add the data at "yyy" from another txt file. How could I do that?
How can I add data from a .txt file to an HTML table?
id name data
-- ---- ----
1 Pirate yyy
2 Monkey yyy
3 Ninja yyy
4 Spaghetti yyy
I would like to add the data at "yyy" from another txt file. How could I do that?
This is not possible without some kind of server side programming language to open up and read the file.
How it works will depend on what language you want to use.
How it works will depend on what language you want to use.
ASKER
Which would you recommend for a beginner and for what I want to accomplish?
Can you post the html you already ?
ASKER
I want to add the time in the "Time" place and replace "xy.z" with actual data.
==
==
<thead>
<tr>
<th scope="col">Date</th>
<th scope="col">POP1</th>
<th scope="col">POP2</th>
<th scope="col">SMTP1</th>
<th scope="col">SMTP2</th>
<th scope="col">SMTP2A</th>
<th scope="col">US.SMTP2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Time</td>
<td>xy.z</td>
<td>xy.z</td>
<td>xy.z</td>
<td>xy.z</td>
<td>xy.z</td>
<td>xy.z</td>
</tr>
<tr>
<td>Time</td>
<td>xy.z</td>
<td>xy.z</td>
<td>xy.z</td>
<td>xy.z</td>
</tr>
<tr>
<td>Time</td>
<td>xy.z</td>
<td>xy.z</td>
<td>xy.z</td>
<td>xy.z</td>
</tr>
<tr>
<td>Time</td>
<td>xy.z</td>
<td>xy.z</td>
<td>xy.z</td>
<td>xy.z</td>
</tr>
</tbody>
</table>
ASKER
Any ideas?
I use php mostly which is pretty simple to learn.
Ok I am going to assume a few things here but hang with me.
Ok I am going to assume a few things here but hang with me.
$filename = "path to file";;
}
if(!empty($filename))
{
$fh = fopen($directory.$filename, 'r');<-open up the file in read only mode
if($fh)
{
$theData = fread($fh, filesize($directory.$filename));<-read file into a string
fclose($fh);<-close file
$dealercopy = explode("\r\n", $theData);<-splits up string based on end of line characters change to match yours
foreach($dealercopy as $value)<-loop through array
{
echo "<tr>date('g')";<-not sure how you want the time formatted its easy to change
$info = explode(" ",$value);<-expecting data formatted like example in question this is so that you can get individual pieces, if columns are tab deliminatted change the " " to "^t"
foreach($info as $piece)
{
echo "<td>$piece</td>";
}
echo "</tr>";
}
woops on line 2 take out the } and on line 1 remove one of the ;
ASKER
Sorry, I have to take a crash course on PHP... Hope to answer back by Monday..
Can you show me an example of the text file your getting yyy from?
How's it formatted?
How's it formatted?
ASKER
It a .txt file, like this without the number lines:
203
304
456
777
888
ok...is it a 1 for 1 thing. The number of rows in your table equal the number of rows in yoru text file?
if not, how do I know which number goes into which row?
ASKER
Yes, it is a 1 text file for each "yyy" data. So from my original question, I would have 4 text files.
id name data
-- ---- ----
1 Pirate yyy (text file1)
2 Monkey yyy (text file2)
3 Ninja yyy (text file3)
4 Spaghetti yyy (text file4)
id name data
-- ---- ----
1 Pirate yyy (text file1)
2 Monkey yyy (text file2)
3 Ninja yyy (text file3)
4 Spaghetti yyy (text file4)
And each text has only one number.
Right? And nothing but that one number?
If so...what is the naming convention of the text files.
Right? And nothing but that one number?
If so...what is the naming convention of the text files.
ASKER
Here is the html, i'm working on the css file.
The text files would take the same name of the table headers.
index.html.zip
The text files would take the same name of the table headers.
index.html.zip
ASKER
Any ideas?
ASKER
Anything?
I keep getting an error opening the index.html from your zip file.
It says
Cannot open file index.html. This file may be open in another application or a read-only copy of the file already exists. If the file is in use, close the open file and try viewing it again.
It says
Cannot open file index.html. This file may be open in another application or a read-only copy of the file already exists. If the file is in use, close the open file and try viewing it again.
ASKER
Ok, let me upload the original file. The date and time would run 24 hours so I am thinking I will have to add more cells in the columns.
Source.zip
Source.zip
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cool, i'll check it this evening..
just make sure that you have a copy of the jquery file when you test it and make sure that it is linked up correctly.
ASKER
Haven't had a chance to try it..
ASKER
Thank you
are you PHP? or ASPx?