How to show table in different ways in different webpages?

I want to create a table of word comparison.

English Thai Vietnamese
Hello สวัสดี Xin chào
My name is ฉันชื่อ Tên tôi là
  • In the page named "Thai Phrases", only the English and Thai columns will appear.
  • In the page named "Vietnamese Phrases", only the English and Vietnamese columns will appear.

My website is built with Drupal so I could basically just create a webpage with the table in Drupal and then mirror it (call it) in any other webpage with Drupal’s Views module, so that changes to the table webpage would effect any other webpage in which the table is mirrored (called at).
But
I still don’t know how best to control columns in respective mirror pages.
I think that display: none with CSS and element.remove() with JavaScript are not really elegant ways to do that and it should probably be done backendly, but how?

Presumably you have all the words in a database of some kind?

2 Likes

I don’t know if this of use to you.

Maybe I have got this wrong, but I think Gandalf is illuding to the fact that you would only fetch the language data you need for a particular page e.g. lang=th would only fetch the English and Thai translations.

On that basis, it is not clear why you would need to hide or remove anything. Just populate a table with English and the specific other language.

2 Likes

Indeed! To fetch all the languages - or to have it hard-coded on a page and just display some of the HTML strikes me as an interesting approach.

1 Like

The webpage that contains the HTML table itself is indeed part of Drupal’s SQL database.

The HTML table with all the languages is one single “hardcoded” HTML table.
Thus
If I mirror it to any webpage, it will naturally appear as is in that webpage (with all three languages).
Therefore
I assume that some kind of hiding is needed. For example, in the webpage that includes only English and Thai, I would need to hide the Vietnamese column.

Or else, instead of mirroring it with Drupal’s Views module you suggest that I would fetch the HTML of the English and Thai, without the Vietnamese part (the entire table, just without the Vietnamese column) but I don’t know a way to do that.

So the table is written purely in HTML. It is not created dynamically by PHP?

That’s not really what I asked. You probably should have a database table with all your words and phrases in each language, like @rpg_digital has linked to.

The text in each table cell together with its HTML is very roughly 25 bytes. So if your table has, say, 40 rows then the data you would save by deleting a column backend would be only one kilobyte approximately. In my view it is not worth messing about backend: simply use CSS to hide a column.

1 Like

It doesn’t have to be a SQL database. A simple CSV would do the trick. Seems to me it would be easier the maintain than an HTM table.

1 Like

It is possible to hide a column using <colgroup> and CSS. Though it would still require a little back-end intervention to tell it what to hide and when, which could be as little as adding a class to the table.
But since you are using Durpal which is PHP/SQL bsed it would seem natural to store the table data in a database table and render dynamically.
The table could be as simple as:-

phrase_id | en | th | vi

Then you select your data:-

if('th' === $lang){ $query = "SELECT `en`, `th` FROM phrase" ;}
elseif('vi' === $lang){ $query = "SELECT `en`, `vi` FROM phrase" ;}

I presume Durpal will have facility to render a table from fetched data. If not, it’s not too difficult to do with a foreach loop.

Exactly

I don’t have anything like that.

@rpg_digital
@Gandalf

Do you know such ready XML-SQL table or JSON-SQL table in GitHub?

I am not experienced in table creation programs like Excel or Calc and I am not a SQL programmer and any case I don’t know how to integrate such a table with Drupal but still reading some ready code in GitHub might help me.

If you are not comfortable working with databases using commands, you can manage them using a GUI like MySql Workbench or PHPmyAdmin. There you can create and populate tables without a lot of code.
I don’t know Durpal, but it probably has tools for working with databases.

1 Like