Facebook Twitter Pinterest

Think Mobile

Table-data in PHP prevents duplication

This file can be used to load the screen size data into a table two different ways, and it can be used by both different files (pixels.html and pixels-js.html) to make sure the data is the same no matter which file we choose in the end.

<?php
  $tableData = array (
    "Desktop|1024|768",
    "Desktop|1680|1050",
    "Desktop 1080|1920|1080",
    "Desktop Cinema|2560|1440",
    "Desktop 4K|3840|2160",
    "iPhone 5|640 (320)|1136 (568)",
    "iPhone 4|640 (320)|960 (480)",
    "iPhone 3|320|480",
    "iPad|768|1024",
    "Android sdpi|320|426",
    "Android mdpi|320|470",
    "Android ldpi|480|640",
    "Android xldpi|720|960",
    "Samsung Galaxy S3/4|360|640",
    "Samsung Galaxy Note|800|1280 ",
    "HTC, LG Optimus, Nexus S|320|533",
    "HTC|480|800",
    "HTC|540|960",
    "LG Optimus Pad|768|1280",
    "MS Surface|768|1366",
    "Droid|360|599",
    "Nexus 4|384|598",
    "Nexus 7|603|966" );

  // ----------------------------------------------------
  // Just print each data entry to a table cell blindly
  // ----------------------------------------------------
  // like this:
  //   +--------------+----------+---------+
  //   |  Desktop     |  1024    |   768   |
  //   +--------------+----------+---------+
  //
  // ----------------------------------------------------
  function showTableRow3Col ($s)
  {
    $cells = split ("\|", $s);
    echo "<tr>";
    for ($i=0; $i<count($cells); $i++)
      echo "<td>" . $cells[$i] . "</td>";
    echo "</tr>\n";
  }

  // ----------------------------------------------------
  // This prints both the normal and the small-screen
  // versions in a way suitable to this particular data.
  //
  // This could be generalized somehow, probably by using
  // formatting strings.
  // ----------------------------------------------------
  // like this:
  //   +--------------+----------+---------+---------------+
  //   |  Desktop     |  1024    |   768   |  1024 x 768   |
  //   +--------------+----------+---------+---------------+
  //
  // ----------------------------------------------------
  function showTableRow4Col ($s)
  {
    $cells = split ("\|", $s);
    echo "<tr>";
    echo "<td>" . $cells[0] . "</td>";
    echo "<td>" . $cells[1] . "</td>";
    echo "<td>" . $cells[2] . "</td>";
    echo "<td>" . $cells[1] . " x " . $cells[2] . "</td>";
    echo "</tr>\n";
  }
?>