fork(1) download
  1. <?php
  2.  
  3. try {
  4.  
  5. /*
  6.   switch (true) {
  7.   case !isset($_REQUEST['date']):
  8.   case !is_string($date = $_REQUEST['date']):
  9.   throw new Exception('日付を指定してください');
  10.   }
  11.  
  12.   $dbname = '';
  13.   $dbuser = '';
  14.   $dbpass = '';
  15.  
  16.   $pdo = new PDO("mysql:dbname={$dbname};host=localhost;charset=utf8", $dbuser, $dbpass);
  17.   $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  18.  
  19.   $sql = 'SELECT * FROM tableA JOIN tableB ON tableA.staff_id = tableB.staff_num WHERE s_date = ?';
  20.   $stmt = $pdo->prepare($sql);
  21.   $stmt->execute(array($date));
  22.   $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
  23.   */
  24.  
  25. $rows = array(
  26. 's_date' => '08-04',
  27. 'staff_id' => '002',
  28. 'cell01' => '10:35,会議室,1',
  29. 'cell02' => '-',
  30. 'cell03' => '-',
  31. 'cell200' => '19:40,フロアB,3',
  32. 'staff_num' => '002',
  33. 'staff_name' => 'A山A男',
  34. 'belong' => 'A支店',
  35. ),
  36. );
  37.  
  38. array_walk_recursive($rows, function (&$v, $k) {
  39. if (strpos($k, 'cell') !== 0) {
  40. return;
  41. }
  42. $values = explode(',', $v, 3);
  43. if (!isset($values[2])) {
  44. $values = array_fill(0, 3, '-');
  45. }
  46. $keys = array('time', 'place', 'flag');
  47. $v = array_combine($keys, $values);
  48. });
  49.  
  50. } catch (Exception $e) {
  51.  
  52. $error = htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8');
  53.  
  54. }
  55.  
  56. ?>
  57. <!DOCTYPE html>
  58. <html>
  59. <head>
  60. <meta charset="UTF-8">
  61. <title>Test</title>
  62. </head>
  63. <body>
  64. <?php if (isset($error)): ?>
  65. <p><?=$error?></p>
  66. <?php elseif (!$rows): ?>
  67. <p>データが見つかりませんでした</p>
  68. <?php else: ?>
  69. <?php foreach ($rows as $row): ?>
  70. <table border>
  71. <caption><?=$row['staff_name']?>(<?=$row['s_date']?>)</caption>
  72. <tr>
  73. <th>場所</th>
  74. <th>開始時間</th>
  75. </tr>
  76. <?php foreach (array_slice($row, 2, -3) as $r): ?>
  77. <?php if ($r['time'] === '-') { continue; }?>
  78. <tr class="style<?=$r['flag']?>">
  79. <td><?=$r['place']?></td>
  80. <td><?=$r['time']?></td>
  81. </tr>
  82. <?php endforeach; ?>
  83. </table>
  84. <?php endforeach; ?>
  85. <?php endif; ?>
  86. </body>
  87. </html>
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<table border>
<caption>A山A男(08-04)</caption>
<tr>
<th>場所</th>
<th>開始時間</th>
</tr>
<tr class="style1">
<td>会議室</td>
<td>10:35</td>
</tr>
<tr class="style3">
<td>フロアB</td>
<td>19:40</td>
</tr>
</table>
</body>
</html>