Reputation: 21
I have made a chatroom where a user types his message into textarea,then the message is sent to the PHP file where it creates an html around the message and then it writes it into a file called log.html
. It also takes the users username and his profile picture.
So previously I had my code looking like this :
<div class='msgln'>
<ul>
<li class='float'><img src='$someimg'></li>
<li class='username_chatroom'><b>username</b></li>
<li class='text_chatroom'><span class='text_span'>Random text</span><li>
</ul>
</div>
Does it make more sense converting the divs to table td ,tr for easier formatting? Would the code then look like this? :
<tr class='tr_chat'>
<td class='img_chat'><img src='$someimg'></td>
<td class='usr_chat'><b>username</b></td>
<td class='msg_chat'>Text text text</td>
</tr>
The only other question I then have is, when I create the file in which this html will be, do I need to define the end of the table? Because when I create a file I can define at the beginning <table>
but I can't end it, because the code would go like this then:
<table>
</table>
<tr class='tr_chat'>
<td class='img_chat'><img src='$someimg'></td>
<td class='usr_chat'><b>username</b></td>
<td class='msg_chat'>Text text text</td>
</tr>
So, is it better to use tables instead of divs for formatting, and if so.. do I need to define the end of a table?
Upvotes: 1
Views: 131
Reputation: 943605
Does it make more sense converting the divs to table td ,tr for easier formatting?
No, but it does make sense to convert to a table because the data is tabular in nature.
Each item in a row has something in common (it is a specific message and the metadata about it).
Each column has something in common (you have sensible headings you can give them).
That is what tables are for.
The only other question i then have is , when i create the file in which this html will be, do i need to define the end of the table??
Yes. The end tag for the table element is mandatory.
Because when i create a file i can define at the beggining but i cant end it,because the code would go like this then
Your problem is that you are trying to use HTML as your database.
Use a real database instead. Generate the HTML from it on demand.
Upvotes: 1