The problem is that JavaScript is client-side and php is server-side. That means that all of the PHP is parsed before being sent to the browser, and then all of the JS is run (once it loads into the user's browser)
What does this mean? Well, you can't define the resolution as a variable using JS and then use it later in the same page. You can probably assign it to a variable and then pass that variable to a new page, but you can't use it in the same page.