HTML code in database

I have a html code that shows the sporting fixtures relevant to specific teams in my database and I need it to change depending on the selected team.

This is an example of the html code I have for one division (I have different codes for the different team divisions:

This is my website:

https://editor.wix.com/html/editor/web/renderer/edit/4ac7b5ae-d42a-4469-8158-3fdef1bed0f5?metaSiteId=9d3bfe20-e1ee-4eb6-8cdc-53a220563dab&editorSessionId=E056428C-8ABD-4596-B101-6FD4EE07E8E4

I’ve put the html code boxes in this page to demonstrate what I would love it to show but as they aren’t able to be “connected to data” I don’t know how to link it up!

Hi Imogen,

Welcome to the Wix Code forums.

If I understand correctly what you want, each team has a different URL which is used in the HTML code.

The HtmlComponent is used in two different ways:

Set the link src to embed an external site/doc/whatever on your page. You could do something like this:

$w("#html1").src = "https://tournament-cloud.com/#T?x=7584&FS=Stage&Embed=true";

(I tried this myself on an experimental page and it worked fine.)

Or, embed code in the HtmlComponent and pass messages back and forth between the page and the HtmlComponent code. Read the article Working with the HTML Component in Wix Code for details on how this is done.

Good luck,

Yisrael

1 Like

Hi Yisrael,

Thanks for the response!

I don’t quite understand? I don’t really know much about coding but I am trying to learn as much as I can as I go.


^ This is my database and I want to create dynamic item page for the different divisions but as each dynamic page requires an embedded html code I am lost.

I want to add the html code into a column in this database and link it to an element on the dynamic page, I just don’t know what element will let it work?

Not sure if what i’m saying makes sense or not?

Thanks

What you’re looking for (I think) is that you want to use the result of a database query to set the link. It might look something like this:

let division = < value from selected table row >
wixData.query("teams")
   .eq("division", division)
   .find()
   .then( (results) => {
      let items = results.items;
      let item = items[0];
      $w("#html1").src = item.link;
   } )
   .catch( (err) => {
      let errorMsg = err;
   } );

This is not complete working or tested code, but rather gives you an idea of what you need to do with the HtmlComponent. What you want should be doable. It just depends on what you envision as acceptable.

In order to accomplish what you’re trying to do you’ll need some proficiency in code. We’re here to help when you run into difficulties.

Good luck,

Yisrael

Hi

I have a HTML code as

I just want to change the data-identifier text (which here is Robert Downey) of the html element which is at dynamic page of my wixsite as my code differ only at data-identifier. and i want to connect this text inside the data identifier component with my database with field named as “Name”. Please tell me how could i do this. I need your help.