Link to home
Start Free TrialLog in
Avatar of mechanicus01
mechanicus01Flag for Mexico

asked on

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?
Avatar of Evan Cutler
Evan Cutler
Flag of United States of America image

what programming do you have?
are you PHP? or ASPx?
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.
Avatar of mechanicus01

ASKER

Which would you recommend for a beginner and for what I want to accomplish?
Can you post the html you already ?
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


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.
$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

woops  on line 2 take out the } and on line 1 remove one of the ;
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?
It a .txt file, like this without the number lines:

203
304
456
777
888

Open in new window

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?
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)

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.
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
Any ideas?
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.
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
ASKER CERTIFIED SOLUTION
Avatar of haloexpertsexchange
haloexpertsexchange
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Haven't had a chance to try it..
Thank you