Change php variable value through media queries

Asked

Viewed 203 times

-3

I need to change the variable value of a function according to the screen resolution (when reducing the screen the value has to be updated immediately). You can change this value through CSS media queries?

I mean, something like this with css:

@media only screen and (max-width: 1065px) {
    $variavel = 3;
}

@media only screen and (max-width: 769px) {
    $variavel = 2;
}

To recover the value in php:

catalogo($variavel);

Is there any way to do this?

Thank you

  • This query does not make much sense. There is no "PHP variable" when the client is accessing the page. There is only PHP while the server mounts the content. Then it goes to the browser, where the darlings will be processed. At most, what you can do is send the screen width via JS or something like that to another PHP store.

  • 1

    Dude, there’s no way you can do it this way no... PHP and CSS don’t match like you think. The ideal would be to take the screen size through Javascript and then pass to PHP, this is possible.

  • Thanks for the answers, I will think of another way to do what I need. Thanks also for the suggestions.

  • @Tiagopereira what the purpose of this code is. Tell us what you intend to do. Maybe we can point a way.

  • Damn, use a Less or a Sass :D

1 answer

2

PHP is a Server Side language and CSS is a Client Side language..

There is no direct communication between them. However, through AJAX it is possible to carry out some communication between the two.

I advise you to read about AJAX, here is a good link to start http://www.w3schools.com/ajax/ajax_examples.asp

However, tell us what you really want to do so that we can show you a better way, I think AJAX will be too complex for what you need..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.