Advertisement
dimipan80

HTML Table

Dec 2nd, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <!--Write a PHP script InformationTable.php which generates an HTML table by given information about a person
  2. (name, phone number, age, address). Styling the table is optional. Semantic HTML is required.-->
  3.  
  4. <!DOCTYPE html>
  5. <html>
  6. <head lang="en">
  7.     <meta content="text/html" charset="UTF-8">
  8.     <title>HTML Table</title>
  9.     <style type="text/css">
  10.         table {
  11.             border-collapse: collapse;
  12.         }
  13.  
  14.         td {
  15.             padding: 5px;
  16.             border: 1px solid #000;
  17.         }
  18.  
  19.         td:first-child {
  20.             background-color: orange;
  21.             //font-weight: 600;
  22.         }
  23.  
  24.         td:last-child {
  25.             text-align: right;
  26.         }
  27.     </style>
  28. </head>
  29. <body>
  30. <?php
  31. function generateHTMLTable($personalData = array('name', 'phoneNumber', 'age', 'address')) {
  32.     echo '<table><tbody>';
  33.     for ($i = 0; $i < count($personalData); $i++) {
  34.         $currentRow = '<tr><td><strong>';
  35.  
  36.         switch ($i) {
  37.             case 0:
  38.                 $currentRow .= 'Name';
  39.                 break;
  40.             case 1:
  41.                 $currentRow .= 'Phone Number';
  42.                 break;
  43.             case 2:
  44.                 $currentRow .= 'Age';
  45.                 break;
  46.             case 3:
  47.                 $currentRow .= 'Address';
  48.                 break;
  49.         }
  50.  
  51.         echo "$currentRow</strong></td><td>$personalData[$i]</td></tr>";
  52.     }
  53.  
  54.     echo '</tbody></table>';
  55. }
  56.  
  57. generateHTMLTable(array('Gosho', '0882-321-423', 24, 'Hadji Dimitar'));
  58. generateHTMLTable(array('Pesho', '0884-888-888', '67', 'Suhata Reka'));
  59. generateHTMLTable();
  60. ?>
  61. </body>
  62. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement