MilaDimitrovaa

RRS 16

Feb 8th, 2022
1,154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.96 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.  
  8.     <title>Table</title>
  9. </head>
  10. <body>
  11.     <h1>Table countries </h1>
  12.  
  13. <?php
  14. $servername = "localhost";
  15. $username = "root";
  16. $password = "";
  17.  
  18. try {
  19.   $conn = new PDO("mysql:host=$servername;dbname=geography", $username, $password);
  20.   // set the PDO error mode to exception
  21.   $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  22.   //echo "Connected successfully";
  23.  
  24.   $query = "SELECT *
  25.  FROM geography.countries;";
  26.   $pdoStatement = $conn->prepare($query);
  27.   $pdoStatement->execute();
  28.   $pdoStatement->setFetchMode(PDO::FETCH_ASSOC);
  29.  
  30.   $data = $pdoStatement->fetchAll();
  31.   $table  = "<table border = '3'>";
  32.   $table .= "<thead>";
  33.   $table .= "<tr>";
  34.   $table .= "<th>Country code</th>";
  35.   $table .= "<th>Country name</th>";
  36.   $table .= "<th>Population</th>";
  37.   $table .= "<th>Capital</th>";
  38.   $table .= "</tr>";
  39.   $table .= "</thead>";
  40.  
  41.   $table .= "<tbody>";
  42.   for($i = 0; $i < count($data); $i++){
  43.         $currentRow = $data[$i];
  44.         $table .= "<tr>";
  45.         $table .= "<td>" .$currentRow['country_code'] . "</td>";
  46.         $table .= "<td>" .$currentRow['country_name'] . "</td>";
  47.         $table .= "<td>" .$currentRow['population'] . "</td>";
  48.         $table .= "<td>" .$currentRow['capital'] . "</td>";
  49.         $table .= "</tr>";
  50.  
  51.   }
  52.  
  53.   $table .= "</tbody>";
  54.   $table .= "</table>";
  55.  
  56.   echo $table;
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. } catch(PDOException $e) {
  64.   echo "Connection failed: " . $e->getMessage();
  65. }
  66. ?>
  67.  
  68. </body>
  69. </html><!DOCTYPE html>
  70. <html lang="en">
  71. <head>
  72.     <meta charset="UTF-8">
  73.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  74.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  75.  
  76.     <title>Table</title>
  77. </head>
  78. <body>
  79.     <h1>Table countries </h1>
  80.  
  81. <?php
  82. $servername = "localhost";
  83. $username = "root";
  84. $password = "";
  85.  
  86. try {
  87.   $conn = new PDO("mysql:host=$servername;dbname=geography", $username, $password);
  88.   // set the PDO error mode to exception
  89.   $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  90.   //echo "Connected successfully";
  91.  
  92.   $query = "SELECT *
  93.  FROM geography.countries;";
  94.   $pdoStatement = $conn->prepare($query);
  95.   $pdoStatement->execute();
  96.   $pdoStatement->setFetchMode(PDO::FETCH_ASSOC);
  97.  
  98.   $data = $pdoStatement->fetchAll();
  99.   $table  = "<table border = '3'>";
  100.   $table .= "<thead>";
  101.   $table .= "<tr>";
  102.   $table .= "<th>Country code</th>";
  103.   $table .= "<th>Country name</th>";
  104.   $table .= "<th>Population</th>";
  105.   $table .= "<th>Capital</th>";
  106.   $table .= "</tr>";
  107.   $table .= "</thead>";
  108.  
  109.   $table .= "<tbody>";
  110.   for($i = 0; $i < count($data); $i++){
  111.         $currentRow = $data[$i];
  112.         $table .= "<tr>";
  113.         $table .= "<td>" .$currentRow['country_code'] . "</td>";
  114.         $table .= "<td>" .$currentRow['country_name'] . "</td>";
  115.         $table .= "<td>" .$currentRow['population'] . "</td>";
  116.         $table .= "<td>" .$currentRow['capital'] . "</td>";
  117.         $table .= "</tr>";
  118.  
  119.   }
  120.  
  121.   $table .= "</tbody>";
  122.   $table .= "</table>";
  123.  
  124.   echo $table;
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131. } catch(PDOException $e) {
  132.   echo "Connection failed: " . $e->getMessage();
  133. }
  134. ?>
  135.  
  136. </body>
  137. </html><!DOCTYPE html>
  138. <html lang="en">
  139. <head>
  140.     <meta charset="UTF-8">
  141.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  142.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  143.  
  144.     <title>Table</title>
  145. </head>
  146. <body>
  147.     <h1>Table countries </h1>
  148.  
  149. <?php
  150. $servername = "localhost";
  151. $username = "root";
  152. $password = "";
  153.  
  154. try {
  155.   $conn = new PDO("mysql:host=$servername;dbname=geography", $username, $password);
  156.   // set the PDO error mode to exception
  157.   $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  158.   //echo "Connected successfully";
  159.  
  160.   $query = "SELECT *
  161.  FROM geography.countries;";
  162.   $pdoStatement = $conn->prepare($query);
  163.   $pdoStatement->execute();
  164.   $pdoStatement->setFetchMode(PDO::FETCH_ASSOC);
  165.  
  166.   $data = $pdoStatement->fetchAll();
  167.   $table  = "<table border = '3'>";
  168.   $table .= "<thead>";
  169.   $table .= "<tr>";
  170.   $table .= "<th>Country code</th>";
  171.   $table .= "<th>Country name</th>";
  172.   $table .= "<th>Population</th>";
  173.   $table .= "<th>Capital</th>";
  174.   $table .= "</tr>";
  175.   $table .= "</thead>";
  176.  
  177.   $table .= "<tbody>";
  178.   for($i = 0; $i < count($data); $i++){
  179.         $currentRow = $data[$i];
  180.         $table .= "<tr>";
  181.         $table .= "<td>" .$currentRow['country_code'] . "</td>";
  182.         $table .= "<td>" .$currentRow['country_name'] . "</td>";
  183.         $table .= "<td>" .$currentRow['population'] . "</td>";
  184.         $table .= "<td>" .$currentRow['capital'] . "</td>";
  185.         $table .= "</tr>";
  186.  
  187.   }
  188.  
  189.   $table .= "</tbody>";
  190.   $table .= "</table>";
  191.  
  192.   echo $table;
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199. } catch(PDOException $e) {
  200.   echo "Connection failed: " . $e->getMessage();
  201. }
  202. ?>
  203.  
  204. </body>
  205. </html>
Advertisement
Add Comment
Please, Sign In to add comment