I want to make a html table using text file data. Since I am new to web designing I dont know which approach would be best. It would be great if anyone would give me pointers on what to do.
Asked
Active
Viewed 1,019 times
-1
-
Please provide the txt file, what you tried so far and what the result should look like. Some googling should point you into the right direction. – Aaron Apr 06 '20 at 08:26
-
My project is to create timetable or schedule of university according to the data. I have made the algorithm of this in c++ and it returns the schedule in a text file. The file contains fields like "Teacher_name, start_time, end_time, batch". Now I want to implement this idea on web and create html table from that but I have no idea on how to do so. – Muhammad Ahmed Apr 06 '20 at 08:35
-
To be clear i am not asking for a complete solution. I am just asking which approach would be best for it. Since I dont know java script and PHP I am asking which one of these 2 will be best for my project. – Muhammad Ahmed Apr 07 '20 at 05:22
-
PHP and JS serve different use cases. JS is used mainly for frontend (can also be used for backend with node for example) and PHP is a plain backend language. I'll show you a simple implementation. – Aaron Apr 07 '20 at 06:42
-
Check my answer and mark it as accepted answer if it helped you – Aaron Apr 07 '20 at 06:51
1 Answers
0
So first off you will have to start with loading the txt file. Since you wrote in the comments about php, i guess you are using PHP as backend language.
So create a file called table.php.
In this file you can load the text file from your server / whatever and also create the html code and echo it. This will return the table line by line.
Another good solution would be to create an object out of your text file and then use JSON as transfer state for this object to your JavaScript frontend -> this is my prefered solution.
It should look similar to this (file load taken from this):
<?php
$html = '<table>'; //html variable will contain our table code
$fh = fopen('filename.txt','r'); //filename / path here
while ($line = fgets($fh)) {
$html .= '<tr>';
$html .= '<td>' + $line + '</td>';
$html .= '</tr>';
}
fclose($fh);
$html .= '</table>';
echo $html;
?>

Aaron
- 1,600
- 1
- 8
- 14
-
Thanks. You cleared many things for me. Now I know that my project is possible. – Muhammad Ahmed Apr 08 '20 at 06:35
-
i have created the table but i cant use css properties on the table why is it? – Muhammad Ahmed Apr 22 '20 at 08:17