HTML / Javascript help
Author
Discussion

Herbs

Original Poster:

5,132 posts

259 months

Wednesday 16th March 2022
quotequote all
Morning,

I have a widget to embed in a website from the CQC which looks as follows:

https://www.cqc.org.uk/guidance-providers/ratings/...

(I can't post it here as PH blocks it


Nice and easy and it works perfectly. However, as they have a few sites, the LocationID is stored in a mySQL database as a alpha-numeric field which I cannot get to populate.

I'm guessing it is because its sitting in the middle of a URL text string, but my coding skills is not sufficient enough to work out the correct way to split and splice together again.

Could anyone advise of the correct way please

Durzel

12,999 posts

198 months

Wednesday 16th March 2022
quotequote all
This is a bit confusing.

Are you saying you have several websites that are powered from MySQL databases (the same one? one or more each?) that all need to embed this widget?

"as they have a few sites", who is they in this context? The company you are doing this work for? Your opening comment talks about embedding this CQC widget in a website, not several.

What language(s) are the website(s) written in that you're trying to embed this widget on?

If you're embedding this widget on multiple websites, and they all use their own distinct MySQL database, and this LocationID doesn't change for each website, why not just hardcode it?

Herbs

Original Poster:

5,132 posts

259 months

Wednesday 16th March 2022
quotequote all
Durzel said:
This is a bit confusing.

Are you saying you have several websites that are powered from MySQL databases (the same one? one or more each?) that all need to embed this widget?

"as they have a few sites", who is they in this context? The company you are doing this work for? Your opening comment talks about embedding this CQC widget in a website, not several.

What language(s) are the website(s) written in that you're trying to embed this widget on?

If you're embedding this widget on multiple websites, and they all use their own distinct MySQL database, and this LocationID doesn't change for each website, why not just hardcode it?
Hi, yes i can understand the confusion. smile

It's one website and one database.

There are various physical sites (nursing homes), not web sites which each have a profile page on the website and their own rating.


maffski

1,905 posts

189 months

Wednesday 16th March 2022
quotequote all
Are you looking to do this on the server before the page is sent, or on the clients browser when the page is displayed?

If it's on the server do you know what your website is written using? For example PHP, Wordpress etc?

Durzel

12,999 posts

198 months

Wednesday 16th March 2022
quotequote all
Herbs said:
Durzel said:
This is a bit confusing.

Are you saying you have several websites that are powered from MySQL databases (the same one? one or more each?) that all need to embed this widget?

"as they have a few sites", who is they in this context? The company you are doing this work for? Your opening comment talks about embedding this CQC widget in a website, not several.

What language(s) are the website(s) written in that you're trying to embed this widget on?

If you're embedding this widget on multiple websites, and they all use their own distinct MySQL database, and this LocationID doesn't change for each website, why not just hardcode it?
Hi, yes i can understand the confusion. smile

It's one website and one database.

There are various physical sites (nursing homes), not web sites which each have a profile page on the website and their own rating.
If it's one website and one database, and this LocationID doesn't need to change, then it seems that pulling it out of the database to stick in the widget code seems like unnecessary overkill.

What reason is the LocationID in the database? Does the LocationID change depending on factors - e.g. does this widget need to be shown alongside search function results for the muitiple sites?

Herbs

Original Poster:

5,132 posts

259 months

Wednesday 16th March 2022
quotequote all
Its written in PHP

The location ID identifies each home and can change annually. It does need to be shown in search results as well.

The widget code is supplied by a 3rd party

anonymous-user

84 months

Wednesday 16th March 2022
quotequote all
So you've just got to grab the LocationID from somewhere in your PHP (server side) and squirt it into that script tag when sent to the client?

Doesn't PHP have {} or $ for inserting variables into 'strings' ?

jonsp

1,805 posts

186 months

Wednesday 16th March 2022
quotequote all
Wouldn't it be easier to just do a replace?

We have this url
https://www.cqc.org.uk/sites/all/modules/custom/cqc_widget/widget.js?data-id=LocationID&data-host=www.cqc.org.uk&type=location


and we just need to replace LocationID with the locationid pulled from a database. Don't do PHP but there must be replace function to do that?


ecs

1,451 posts

200 months

Thursday 17th March 2022
quotequote all
Guessing you've got a page per location and your pulling all the info for it from the database? Would need to see the code, but as a total stab in the dark, you'd need to echo the location id from the row returned from the database into the widget url server side:

<?=$row->locationID ?>

I'm a freelance software engineer and do a fair bit of PHP work, DM me if you need some further support with this smile

Herbs

Original Poster:

5,132 posts

259 months

Thursday 17th March 2022
quotequote all
Message sent thumbup

maffski

1,905 posts

189 months

Thursday 17th March 2022
quotequote all
PHP wise the easiest is just:


$locationID = ....get it from database somehow...

echo "https://www.cqc.org.uk/sites/all/modules/custom/cqc_widget/widget.js?data-id=" . $locationID . "&data-host=www.cqc.org.uk&type=location";