• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

Insert Data into HTML Table from Text file

Hello
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

Open in new window


I would like to add the data at "yyy" from another txt file. How could I do that?
0
mechanicus01
Asked:
mechanicus01
  • 13
  • 6
  • 6
1 Solution
 
Evan CutlerVolunteer Chief Information OfficerCommented:
what programming do you have?
are you PHP? or ASPx?
0
 
haloexpertsexchangeCommented:
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.
0
 
mechanicus01Author Commented:
Which would you recommend for a beginner and for what I want to accomplish?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Evan CutlerVolunteer Chief Information OfficerCommented:
Can you post the html you already ?
0
 
mechanicus01Author Commented:
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>                

Open in new window


0
 
mechanicus01Author Commented:
Any ideas?
0
 
haloexpertsexchangeCommented:
I use php mostly which is pretty simple to learn.
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>";
}

Open in new window

0
 
haloexpertsexchangeCommented:
woops  on line 2 take out the } and on line 1 remove one of the ;
0
 
mechanicus01Author Commented:
Sorry, I have to take a crash course on PHP... Hope to answer back by Monday..
0
 
Evan CutlerVolunteer Chief Information OfficerCommented:
Can you show me an example of the text file your getting yyy from?
How's it formatted?
0
 
mechanicus01Author Commented:
It a .txt file, like this without the number lines:

203
304
456
777
888

Open in new window

0
 
Evan CutlerVolunteer Chief Information OfficerCommented:
ok...is it a 1 for 1 thing.  The number of rows in  your table equal the number of rows in  yoru text file?
0
 
Evan CutlerVolunteer Chief Information OfficerCommented:
if not, how do I know which number goes into which row?
0
 
mechanicus01Author Commented:
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)

0
 
Evan CutlerVolunteer Chief Information OfficerCommented:
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.
0
 
mechanicus01Author Commented:
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
0
 
mechanicus01Author Commented:
Any ideas?
0
 
mechanicus01Author Commented:
Anything?
0
 
haloexpertsexchangeCommented:
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.
0
 
mechanicus01Author Commented:
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
0
 
haloexpertsexchangeCommented:
ok what I have got requires javascript and php to work but it will successfully pull information from a text file.
I have 2 text files with the information needed.
One php file to use to read and extract information from the text files.
A javascript file using jquery to pull that information from the php file using ajax and then fill in the information on the html file.

source.zip
0
 
mechanicus01Author Commented:
Cool, i'll check it this evening..
0
 
haloexpertsexchangeCommented:
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.
0
 
mechanicus01Author Commented:
Haven't had a chance to try it..
0
 
mechanicus01Author Commented:
Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 13
  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now