Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using Ajax, this is what needs to be done</p> <pre><code>&lt;html&gt;&lt;body&gt; &lt;div id="content"&gt;&lt;/div&gt; .... &lt;script&gt; $(function(){ $.ajax({ url: 'file.php', type: 'GET', data: {h: screen.height, w: screen.width} }).done(function ( data ) { document.getElementById("content").innerHTML=data; }); }); &lt;/script&gt; </code></pre> <p>That file.php would then run your database query and return a nicely formatted set of results (i.e. html table) based on the h and w parameters sent via ajax which tell you the height and width of the screen. To do this just set the $page variable depending on the size of the <code>$_GET['w']</code> and <code>$_GET['h']</code> variables. See below:</p> <pre><code>&lt;?php // get the function include_once ('function.php'); $maxresults = 21; $page = ( $_GET['page'] ? $_GET['page'] : 0 ); if(($_GET['w']) &amp;&amp; ($_GET['h'])) { $w = $_GET['w']; $h = $_GET['h']; //$maxresults = // calculate this depending on w and h // i.e. if h &gt; 1600 $maxresults = 20, else = 10 $currentpage = $page; $page = $page * $maxresults; $numpages = QuickQuery("SELECT COUNT(id) FROM books WHERE visible=1"); $numpages = mysql_result($numpages, 0); $numpages = $numpages/$maxresults-1; $result = GetBooksByRangeID($page, $maxresults);//Show &lt;maxresults&gt; pages at a time //DisplayResults($result); echo $results; // in a nice format (i.e. table) to be inserted into div via ajax ?&gt; </code></pre> <p>You can calculate $maxresults as follows:</p> <pre><code>if($w &gt; 640) &amp;&amp; ($h &gt; 480) $maxresults = 5; if($w &gt; 800) &amp;&amp; ($h &gt; 600) $maxresults = 7; if($w &gt; 1024) &amp;&amp; ($h &gt; 768) $maxresults = 12; .... if($w &gt; 2560) &amp;&amp; ($h &gt; 1600) $maxresults = 21; </code></pre> <p>Or you can group these statements by width (as I think thats less important than height, meaning less scrolling down for the user):</p> <pre><code>if ($w &lt;= 1024) { if ($h &gt;= 768) $maxresults = 12; // 1024x(768 or higher) else if ($h &gt;= 600) $maxresults = 8; // 1024x(600~768) else $maxresults = 6; // 1024x(599 or below) } else if ($w &lt;= 1280) { if ($h &gt;= 1024) $maxresults = 14; // 1280x(1024 or higher) else if ($h &gt;= 960) $maxresults = 12; // 1280x(960~1024) else if ($h &gt;= 800) $maxresults = 10; // 1280x(800~960) else if ($h &gt;= 768) $maxresults = 8; // 1280x(768~800) else $maxresults = 6; // 1280x(768 or below) } //and so on </code></pre> <h2>see: <a href="http://en.wikipedia.org/wiki/Display_resolution#Computer_monitors" rel="nofollow">http://en.wikipedia.org/wiki/Display_resolution#Computer_monitors</a></h2> <p>Revision</p> <p>You code for populating maxresults is very poorly written, thats why it does not work. Try this:</p> <pre><code>&lt;?php include_once ('function.php'); $maxresults = -1; if(($_GET['w']) &amp;&amp; ($_GET['h'])) { $w = $_GET['w']; $h = $_GET['h']; if ($w == 1920) { $maxresults = 24; } else if ($w == 1600) { $maxresults = 24; } else if ($w == 1440){ $maxresults = 12; } else if ($w == 1366) { $maxresults = 10; } else if ($w == 1024) { $maxresults = 8; } else $maxresults = 6; } echo $maxresults; </code></pre> <p>This will either output -1 if w and h are not being sent or it will return 24 or 12 and so on depending on your screen width. Learn to do some basic debugging on your code. It is difficult for me to debug your code without having all of it to hand.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload