create tables and cells through php
Moderator: General Moderators
create tables and cells through php
Hello. I'm a beginner so please keep answers simple. What I want to do is create a table based on information read from a text file off the server. This has zero to do with databases: it's just simple creations of table cells. I've seen people do it in javascript but it's hard to find someone who knows how to do it in php and without going crazy with databases. I just want to know the simple pieces of code to use, or where to look. Thanks in advance for any help.
Re: create tables and cells through php
creating a table in php is same as creating a table in html
in html
Where as in php you can write it straight away as echo
in html
Code: Select all
<table><tr><!--Table row--><td>Cell 1 data</td><td>Cell2 data</td></tr></table> Code: Select all
echo "<table><tr><td>Cell1data</td><td>Cell2data</td></tr></table>";
Re: create tables and cells through php
I mean actually creating the table cells based on dynamic data... not an initial setup. So the php web page will read a txt file from the server and might find there's 10 values to put into a table that day, so it creates 10 tables cells. Tomorrow it might have 15.
Re: create tables and cells through php
Do you want multiple columns? How does the data need to display?
To achieve this you need to use logic loops until all the data from the text file has been echoed.
To achieve this you need to use logic loops until all the data from the text file has been echoed.
Re: create tables and cells through php
I'm either going to do 2 columns per row or 3 columns per row, then keep adding rows till the end of file is reached. I'll definitely use if/else statements. I just want to know specifically what syntax code to use, like maybe there's some code "createcell()". From there, I'll do my own research on how to use it.
Example for the display:
5 pieces of data:
A B C
D E
10 pieces of data:
A B C
D E F
G H I
J
Example for the display:
5 pieces of data:
A B C
D E
10 pieces of data:
A B C
D E F
G H I
J
Re: create tables and cells through php
There's no function like that.
Look up foreach loops...
http://uk2.php.net/manual/en/control-st ... oreach.php
Best thing to do is load all the values from the text file into an array and then use the foreach loop to ittirate throuhg each one.
You simply echo a <td> and </td> tag in the loop so each time it goes throuhg it will create a new cell.
Make sense?
Look up foreach loops...
http://uk2.php.net/manual/en/control-st ... oreach.php
Best thing to do is load all the values from the text file into an array and then use the foreach loop to ittirate throuhg each one.
You simply echo a <td> and </td> tag in the loop so each time it goes throuhg it will create a new cell.
Make sense?
Re: create tables and cells through php
Gotchya, that makes sense.
Thank you both for your help. I'm rdy to start getting this thing going.
Thank you both for your help. I'm rdy to start getting this thing going.
Re: create tables and cells through php
Check out this PEAR module:
http://pear.php.net/package/HTML_Table/
It's maybe more than you need, but it's worth at least looking at it to see how they did it. It can give you ideas.
http://pear.php.net/package/HTML_Table/
It's maybe more than you need, but it's worth at least looking at it to see how they did it. It can give you ideas.