0

I've researched this topic a bit but unfortunately haven't come up with many results, and I'm struggling to also word it. I apologize if this has been asked before.

I'm currently working on a university assignment that involves creating a dynamic web application for a video game review website. It's going pretty well for my first foray into JS and PHP, however, I've gotten stuck right at the end. The requirement is that the site needs to use JSON for storing data, and as such, I have a JSON file for the games uploaded to the site. Each game needs to have its own page. I know that I can have a base page for the games, and use JS to grab the data from the server and generate the contents from that.

Is it possible for me to create "dynamic" links to these pages? My idea was to store a variable in the URL, where the variable matches up to an ID for a game, but I'm unsure if this is possible.

Unfortunately I have no code to share that would be of use, and I am unsure of where to begin with this problem.

Thanks.

EDIT: To further explain my issue, a massively shortened version of the JSON file would be this:

[
    {
        "id": 1,
        "name": "foo",
        "description": "bar"
    },
]

And with this, there would be a sort of "boilerplate" page, let's call it gameview.html. Upon searching up the URL, for example, somename.com/whatevermethodforgoingtothespecificgamehere, the JS on page load would successfully load the content from the json on the server, using the URL.

Noba
  • 1
  • 1
  • If you "have a JSON file for the games", you could use PHP to`json_decode` that on every page load, and output the data accordingly ... or use PHP to load the file into a javascript variable, and use javascript to generate the output. Is this more or less what you mean? – designosis Mar 01 '22 at 23:04
  • Thanks for the reply - I know how to grab the data from the JSON file, since I've been using that a lot before. However, I'm trying to think of a method for there to be a dynamic link, where upon going to the URL, the JS script will know, from that URL, which specific game entry in the JSON file to grab the data for. I've added an edit to try and explain my issue further, but I've always been bad at explaining things haha @neokio – Noba Mar 01 '22 at 23:09
  • Sounds like you just need to learn how to parse the url/location with javascript, then use that as a key for your JSON array ... something like https://stackoverflow.com/q/4140324/864908 should help – designosis Mar 01 '22 at 23:20
  • Thank you! I'll take a look at that. – Noba Mar 01 '22 at 23:23

0 Answers0