PlayerWet
PlayerWet

Reputation: 419

Detecting resolution and orientation with php

I happen to have this php code that displays records in a gallery. I wish that if a mobile device is vertically oriented and would show only 10 images.

My idea would be to include a conditional depending on resolution have the device to display more or fewer images.

require_once("conexion.php");

$RegShow=20;

if(isset($_GET['pag'])){
    $RegistrosAEmpezar=($_GET['pag']-1)*$RegShow
    $PagAct=$_GET['pag'];

}else{
    $RegistrosAEmpezar=0;
    $PagAct=1;
}

I'm trying to make a responsive web and not well suited if I put so many images at once.

My problem is I do not know if there was anything to detect with PHP or should serve a different php file using JS depending on the resolution.

Thanks.

Upvotes: 0

Views: 2110

Answers (2)

Huzaib Shafi
Huzaib Shafi

Reputation: 1138

You should let AJAX download the code or images and insert it into a given tag on client side. You can retrieve the screen information from javascript and pass it on to PHP using AJAX POST/GET request ... and act accordingly.

JAVASCRIPT/JQUERY

$.ready(function(){
    $.get("images.php?width="+$(window).width()+"&height="+$(window).height(), function(data, status){
    alert("Data: " + data + "\nStatus: " + status); //or insert the returned data into some div
});

});

In images.php

<?php

require_once("conexion.php");
$width = $_GET['width'];
$height = $_GET['height'];

//Now you can retrieve accordingly..

I hope this gives you enough for a clue, or should I explain more...??

Upvotes: 1

Tiega
Tiega

Reputation: 387

I would recommend to do this with CSS its more powerfull. You can use for example:

@media (min-width: 768px) and (max-width: 991px){ //STYLE STUFF }

to create different styles for different Resolution

Upvotes: 1

Related Questions