?
Solved

Insert Data into HTML Table from Text file

Posted on 2011-10-18
25
Medium Priority
?
277 Views
Last Modified: 2012-05-12
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
Comment
Question by:mechanicus01
  • 13
  • 6
  • 6
25 Comments
 
LVL 9

Expert Comment

by:Evan Cutler
ID: 36988834
what programming do you have?
are you PHP? or ASPx?
0
 
LVL 13

Expert Comment

by:haloexpertsexchange
ID: 36988926
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
 
LVL 1

Author Comment

by:mechanicus01
ID: 36989622
Which would you recommend for a beginner and for what I want to accomplish?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 9

Expert Comment

by:Evan Cutler
ID: 36989626
Can you post the html you already ?
0
 
LVL 1

Author Comment

by:mechanicus01
ID: 36989698
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
 
LVL 1

Author Comment

by:mechanicus01
ID: 36996065
Any ideas?
0
 
LVL 13

Expert Comment

by:haloexpertsexchange
ID: 36996192
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
 
LVL 13

Expert Comment

by:haloexpertsexchange
ID: 36996198
woops  on line 2 take out the } and on line 1 remove one of the ;
0
 
LVL 1

Author Comment

by:mechanicus01
ID: 37040661
Sorry, I have to take a crash course on PHP... Hope to answer back by Monday..
0
 
LVL 9

Expert Comment

by:Evan Cutler
ID: 37041066
Can you show me an example of the text file your getting yyy from?
How's it formatted?
0
 
LVL 1

Author Comment

by:mechanicus01
ID: 37041318
It a .txt file, like this without the number lines:

203
304
456
777
888

Open in new window

0
 
LVL 9

Expert Comment

by:Evan Cutler
ID: 37041340
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
 
LVL 9

Expert Comment

by:Evan Cutler
ID: 37041343
if not, how do I know which number goes into which row?
0
 
LVL 1

Author Comment

by:mechanicus01
ID: 37041798
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
 
LVL 9

Expert Comment

by:Evan Cutler
ID: 37041829
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
 
LVL 1

Author Comment

by:mechanicus01
ID: 37041954
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
 
LVL 1

Author Comment

by:mechanicus01
ID: 37054026
Any ideas?
0
 
LVL 1

Author Comment

by:mechanicus01
ID: 37061032
Anything?
0
 
LVL 13

Expert Comment

by:haloexpertsexchange
ID: 37062961
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
 
LVL 1

Author Comment

by:mechanicus01
ID: 37063780
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
 
LVL 13

Accepted Solution

by:
haloexpertsexchange earned 1000 total points
ID: 37064209
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
 
LVL 1

Author Comment

by:mechanicus01
ID: 37064323
Cool, i'll check it this evening..
0
 
LVL 13

Expert Comment

by:haloexpertsexchange
ID: 37064339
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
 
LVL 1

Author Comment

by:mechanicus01
ID: 37148688
Haven't had a chance to try it..
0
 
LVL 1

Author Closing Comment

by:mechanicus01
ID: 37286695
Thank you
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question