tags:

views:

497

answers:

8

I know it's told to use table for tabular data, but I see in many websites and CMS that they use div for showing database content , for example in admin area for editing them, shouldnt they use table for showing these data ? What's the best way ?

A: 

Table because it is data.

David Basarab
+5  A: 

Use a table, since it's tabular data. Unordered, ordered, or dictionary lists should be used when you want to present data in a non-tabular fashion, like the list of questions on the front page of SO.

Stuart Branham
I think you need to know what the data is a little better before making this assumption
Joe Philllips
Agreeing that markup choices should be mindful of data. But the question referenced "database content," which if we're talking RDBMS, is tabular in nature. Hence, tables. A list of foos? Sure, it might not be, which is why I suggest list markup.
Stuart Branham
A: 

search engines more like div

e-turhan
No they don't take this into consideration. Google what google said about the subject.
marcgg
A: 

I will answer your question with another question :

Do you want your data to remain presentable if CSS are not available ?

Yes, definitively go for Tables

No, it's up to you, whichever makes you all warm and fuzzy inside ;-)

Newtopian
I think the semantic way is to use table because it is for showing tabular data, but i saw many sites that don't use this approach !
Datis
true, There are cases when tabular data can be better served though DIV rather than tables (if you need to "relook" the whole thing to alter the tabular nature of the data). However I would tend to think that many of them are chronic consumers of advil when comes time to change the way the data looks.I build a lot of HTML templates for medical data and put CSS to good use to wow! users that are used to 1960 era looking reports. However if for some reason the CSS is offline I still want the report to bear the same meaning. Loosing tabular nature in this case is out of the question
Newtopian
A: 

Div is more widely supported by browsers, while table has some quirks and exceptions that make it cumbersome. a div is more general purpose, you can do a lot with it, not just tables. take a close look at:

http://www.w3schools.com/tags/tag_DIV.asp

Ami
There is very little that you can do with div itself. Style sheets can do a lot and are often used in combination with divs, but the spec explicitly warns against using style sheets to replace elements with the correct semantic meaning. There is no point in writing an 'HTML' document that consists of nothing but div soup.
David Dorward
+1  A: 

Typically you would use DIVs for page layout and TABLEs to display tabular data. In your question you ask about the admin areas for a CMS. If in the admin area they are displaying a grid that represents one or more tables in a database then yes it would probably be best displayed as a table.

However the distinction should be made based on how you are actually presenting the data. Just because the data started out as tabular data (in a database table) doesn't mean that it is inherintly tabular data. If you intend to display it in some other form then DIVs might be the better choice.

Mark Kanof
+1  A: 

It completely depends on what type of data we are talking about. Unless you can give an example of the data, then you won't get a very good answer.

Edit: Per your comment, yes, use a table. If you're showing lists of things from a database then you should use a LIST. There is no golden rule -- the format you use should reflect the data coming from the database.

Joe Philllips
Showing data from database to user, for example list of product with price, category, picture, quantity and so on ....
Datis
A: 

The best markup to use to present a piece of data is always that which is most semantically appropriate. This, of course, raises the question of exactly what is semantically appropriate. This is not a trivial question, and it depends entirely on the sort of data that you're presenting. If your data is tabular in nature, then you should definitely put it in a table. Most data is not tabular in nature, so it shouldn't go in a table.

The reason that using tables is discouraged is because they have historically been misused for non-semantic presentational purposes. Often, authors would place data that wasn't even remotely tabular in nature inside a table tag solely to get it to appear a certain way. This is poor practice, and one should instead create the desired appearance using CSS. This criticism, however, applies not to the use of tables in general, but merely to the use of tables for inappropriate content.

To address a couple of other things:

  • Don't worry about browsers without CSS. This isn't a problem in this day and age, unless you're using non-graphical browsers.
  • Search engines prefer semantic content. If tables are the proper semantics, then the search engines will prefer them.
Thom Smith
Do worry about browsers without CSS — but only insofar as to avoid accidentally encoding *meaning* in the style sheet. If the document doesn't make sense without CSS then you are going to cause problems for users (including search engines and screen reader users).
David Dorward