Host multiple pages in one page - javascript

I want to know How to have pages like YouTube's watch page, http://www.youtube.com/watch?v=abc123 ?
I need it to do the following:
when just going to the main file watch.php, I want it to :show certain code for when they go to that page,
when they go to example /watch?v=abc123, I want it to : show different code only for that link.
I also don't want the main watch.php page to be all cluttered up with code as I'll be at nearly 50+ times using these ?v= I heard you can use Databases but I don't know.
Just whichever ones the best and easiest to make also please try and get it not to be clustered up and easy for me to edit. Thank you
Please Edit this if needed. My website and page i'll be using

This is only available via php. Using $_GET method.
Basically, the link is only www.mysite.com/watch.php. But if you use watch.php?v=123 then the $_GET['v'] will have the value of 123.
For more info: http://www.php.net/manual/en/reserved.variables.get.php
EDIT: basically your step would be like this
Set up a database. This depends on where you host your site. But most host service allow you to create and manage database.
Create a table with values you wanted to store.
Get the "v" value through $_GET
Run queries to connect to the database, and get the stored value. Ue echo to print it out on HTML

Related

How to get the link of table from where data is coming onto html?

For example there is a table like in this link https://leetcode.com/contest/weekly-contest-309/ranking
How to access the database from where it is coming. Like let's say to get whole ranking table at a place
I tried reading HTML file but didn't get it
One extension scrapes the table only
How can we achieve this?
There is no simple answer here - it really depends how is it implemented on the server side. As rv.kvetch pointed you can get part of result from url:
https://leetcode.com/contest/api/ranking/weekly-contest-309/?pagination=1&region=global
You can notice pagination query parameter here, indeed you can access second page, third page and so on. Sometimes there is some parameter like page_size implemented on server but it doesn't look like that case.
So to access full table you probably need to iterate over that pages and glue the results.
EDIT: How to get such url for some page?
Open your favorive browser, run web inspector (usually right click - inspect) and go to network tab, where you can find all requests sent during page rendering.

Get a var value from specific webpage

For example the webpage : www.test.com/a123 has a var called Value that stores quantity of products
the webpage www.test.com/b123 has the same variable also.
On the console of each page, I can call the variable and get their values, but there is some way to get this values without being on that specific page?
I need to get the value table from this pages having only to specify which page I would like.
Something like :
document.getElementByClassName('tamanho__item_pdpjs-tamanho__item_pdp')[5]
But for variables referencing from which page to get
Use the localStorage property of JS.
localStorage.setItem("a123", "value");
// Retrieve on b123 page
document.getElementById("result").innerHTML = localStorage.getItem("a123");
It sounds like you might be struggling to understand where state should live in your application.
The example you mentioned in the comments, Nike and the "SKUsSizes" is likely getting that data from a backend API. Not by accessing a variable on another "web page".
This would be easier to explain if you had a more concrete example but say you need the page b123 to know how many products there are for a123.
The b123 page would make an HTTP request to your backend API requesting details about a123 which may include the number of products.
This data would be stored in a database.
On the other hand, if the product count is coming from some user action that happens over on a123 and you want to see that state change on page b123 then using local storage as suggested in another answer might be one way to solve that problem.
Although it's probably a better idea to use a framework like React, Vue or Angular and use the state management options they have instead of trying to figure out how to do this from scratch.

Updating a page from another page whats the best and easy way?

So my problem is if there are 2 pages for example. PricePage.html has the list of prices and UpdatePrice.html has the input text and etc. If I use the UpdatePrice.html to change the prices of PricePage.html, whats the best way should I use? via php to php or via php to mysql or theres even an easier way to do it. Sorry for my bad english.
Don't think of it as updating one page from another. Think of it as two separate pages that both interact with a database.
Store your price information in a database (such as MySQL).
Have PricePage query the database to get the price information, and generate the HTML to display it. (This means the page can't be just static HTML; it needs to use something like PHP that can generate HTML dynamically.)
Have the UpdatePrice page store the new price information in the database. (This doesn't directly modify PricePage, but next time someone views that page, it'll retrieve and display the latest information in the database.)
If you want the data to get updated in real time like once the data is updated it gets reflected on other page,then you can use sockets which will listen for the update event and once the event is fired the contents will get updated.
One of the most popular framework for this business is socket.io.
I would suggest you to have a look to it.The benefit for using this approach is that you save a lot of resource and the functions work in realtime.

Saving dynamically created content to server & load from there

So I have this webpage that I'm making which allows people to create elements on the page on the fly. And I want to be able to save those elements to my server and whenever someone else reloads that page, the webpage will have those saved elements.
I'm not a good web programmer by any means, so take it easy with the web jargon xD
The user created elements are nested 's or lists. Those elements can be deleted at anytime as well.
So I was reading about saving them as JSON but how would I go about doing that as my 's, most of the top level ones will have the same class. Never worked with JSON before, so I'm a real noob at that.
Will the server file keep replacing itself with a brand new copy with each addition/deletion?
And I'd like to get a little help with showing the new elements without updating. On other users page. I read about AJAX real-time updating, like APE, but have no idea how to go about with that. (This is not really needed but would be a nice one to have)
If someone can guide me a little at least, that will be great. Thanks.
The best suitable way to accomplish this is by saving your objects attributes to a database, however other options include XML files etc..
The process of accomplishing it through database is:
If you want to save data to database then you will have to use a server side language like Php or Asp.net, so first step will be to have a database then an active connection to your database on your intermediate file (lets say 'data.php')
Then you need to code your data.php file so that it can take input(usually through GET or POST method) and it can save it to your database
Then you need to pass your data (objects attributes) through AJAX to data.php and save them to your database
On the main file you will have to check whether already some data exists for user, if yes then fetch it from database and display objects accordingly, otherwise set the objects preferences to default

Special URL for language selection?

Just a simple question, I was wondering why some websites have something like "?lang=EN" in their URL after selecting a language? Is it because their html file or folder containing it is named "?lang=EN", or some other code that does this? I'd like to set the URL like that for my website (has 2 languages). Currently I have folder structure like this:
Language selection: D:/media/index.html
EN site: D:/media/en/index.html
CN site: D:/media/cn/index.html
Files for the website: D:/media/site
Thanks.
First of all, anything after the file extension ( .html ) is a server side function.
The ? is a function for PHP and adds variables to the super global GET array ( in the form: ?variable=value&variable2=value2 ) that is directed to from another page and from that point many things can be done with the data.
Sites that use the ?lang=EN are probably programmed to print out the chunks of text needed on the single page in the places and languages required. Though it is possible using this method to redirect to a language specific directory.
Hope this helps :)
That's because they often have a content management system where the content isn't stored in files necessarily, but in a database. The lang=en is a GET variable from the URL that they retrieve in, for example, PHP, to display the correct content. In your case, however, you can just redirect the user if they click EN or CN to the appropriate locations, in your case, /en/index.html and /cn/index.html.
The url you see at the address bar, whatever comes after "?" is called "QueryString" and with libraries on the server side (based on the developing platform that website is made on) you can access the values. For instance the value of "lang" can be equal to "EN" or "CN" etc.
By the way you can have some http handlers to rewrite the requested url and get your parameters through the url that physically doesn't exists. Like the one you mentioned, "http://yoursite.com/en/default.whatever". I myself prefer this way but as you requested you should use some server side libraries to access the query string values and choose the language of the content you wanna send to client.
Also as one solution that once I used, you can also use some translation service (like translate.google.com) client libraries and call it at client side with jquery or even javascript and translate all the texts on page load. Although it's damn fast in action, it has some issues you will see.
Hope it helps.
PHP uses $_GET to get value from variables from the URL.It gets the value from that LANG variable and then it selects all from a file where are stored all the words in different languages or from the database
You don't need to copy every file and then translate it.
Search for php dynamic pages tutorial in your case. I found THIS.
P.S. PHP is one from many ways to do this.

Categories

Resources