-3

i am using media queries to adjust website layout.

My question is: How to show different number of items in slider based on screen size?

for small screens i echo this:

<?php if($i == 4) {echo '</li><li>';} ?>

on big screens i need to echo this:

<?php if($i == **3**) {echo '</li><li>';} ?>

how to set this using only php? is there any workaround?

Thanks

Warrior
  • 1
  • 2

2 Answers2

0

Short answer: you cannot.

Long answer: since PHP runs on the server, it has absolutely no way of knowing where it will be displayed, or if it actually will be displayed; let alone what is the size of that display. The server has no access to that information. There are some workarounds involving AJAX and sending parameters and reloading the page, and various other hacks; but in the end, you should accept that PHP is an unsuitable tool for the task, and use something like JavaScript to update the styles.

aaaaaa123456789
  • 5,541
  • 1
  • 20
  • 33
  • thanks, i think i'll go with something like this: if(width == 1920){ $("#myDiv").load("book1.php"); } else { $("#myDiv").load("book2.php"); } – Warrior Sep 01 '13 at 11:51
0

You can achieve this by echoing everything twice, with necessary modifications for big screens and mobile screens.

<div class="mobile-only">
  <!-- Echo your stuff for mobiles -->
</div>
<div class="big-screen-only">
  <!-- Echo your stuff for full-sized screens -->
</div>
<!-- Maybe more -- depending on your requirements -->

Then have your media queries hide the .mobile-only on normal screens and vice versa. Although this seems like a bit of an overkill, I guess for most cases this is totally normal.

Update: posting media queries that will do the job (correct them as you see fit)

@media screen and (max-width:480px) {
  .big-screen-only { display: none }
}

@media screen and (min-width:481px) {
  .mobile-only { display: none }
}
BorisOkunskiy
  • 1,830
  • 1
  • 19
  • 24