実現したいこと
初心者です。言葉足らずなところがありますがご教授宜しくお願い致します。
それでは、今回実現したいことは飲食店などの待合にある「お呼び出し番号」のような仕組みです。それをウェブサイト上で再現したいと思い該当のソースコードを書きました。
その内容は、「num.php」に表示された1-300までの数字をクリックすると、その数字の文字サイズが小さくなりクリック済みであることがわかります。そして、それが「disp.php」の表記にも反映されるという仕組みです。ちなみに、両ページとも1秒ごとにリロードしています。
「XAMPP」ではそれが実行できたのですがサーバー上ではできなくなりました。ただ、「Cont+F5」を押すと実行されることがわかりました。
発生している問題・分からないこと
リロード以外のサイトの更新方法がわからないことが問題点です。
該当のソースコード
num.php
1<!DOCTYPE html> 2<html> 3<head> 4<meta charset="UTF-8"> 5 6<script> 7 setInterval(function() { 8 location.reload(); 9 }, 1000); 10</script> 11 12<style> 13.example3{ 14 border-radius: 50%; 15 display: flex; 16 justify-content: center; 17 align-items: center; 18 width: 120px; 19 height: 120px; 20 background: #6fa1ff; 21 color: #FFF; 22 text-decoration: none; 23 text-align: center; 24 margin: 10px 0; 25} 26</style> 27 28<title>番号を押すページ</title> 29</head> 30<body> 31 32文字【小】→番号を押した</br> 33文字【大】→まだ番号を押していない</br> 34 35<?php 36 37try 38{ 39 40$dsn='mysql:dbname=db;host=???;charset=utf8'; 41$user='user_name'; 42$password='pass'; 43$dbh=new PDO($dsn,$user,$password); 44$dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); 45 46$sql='SELECT no,on_off FROM num WHERE 1'; 47$stmt=$dbh->prepare($sql); 48$stmt->execute(); 49 50$dbh=null; 51 52print '<table border="0" cellspacing="15">'; 53print '<tr>'; 54 55for($i=1;$i<=300;$i++) { 56 57if ($i % 10==0){ 58 59while(true) 60{ 61 $rec=$stmt->fetch(PDO::FETCH_ASSOC); 62 if($rec==false) 63 { 64 break; 65 } 66$i=$rec['no']; 67 68if($rec['on_off']==1){ 69 70print '<td><a href="num_add.php?num='. $rec['no'].' & on_off=0" class="example3"><font size="2">'. $rec['no'].'</font></a></td>'; 71}else{ 72print '<td><a href="num_add.php?num='. $rec['no'].' & on_off=1" class="example3"><font size="10">'. $rec['no'].'</font></a></td>'; 73} 74 75if ($i % 10==0){ 76print '</tr>'; 77 78} 79} 80 81} 82} 83 84 85} 86catch (Exception $e) 87{ 88 print '障害発生'; 89 exit(); 90} 91 92?> 93 94 95</body> 96</html>
disp.php
1<!DOCTYPE html> 2<html> 3<head> 4<meta charset="UTF-8"> 5 6<script> 7 setTimeout(function() { 8 location.reload(); 9 }, 1000); 10</script> 11 12<style> 13.example3{ 14 border-radius: 50%; 15 display: flex; 16 justify-content: center; 17 align-items: center; 18 width: 180px; 19 height: 180px; 20 background: #6fa1ff; 21 color: #FFF; 22 text-decoration: none; 23 text-align: center; 24 margin: 10px 0; 25} 26</style> 27 28<style> 29.example4{ 30 border-radius: 50%; 31 display: flex; 32 justify-content: center; 33 align-items: center; 34 width: 80px; 35 height: 80px; 36 background: #6fa1ff; 37 color: #FFF; 38 text-decoration: none; 39 text-align: center; 40 margin: 10px 0; 41} 42</style> 43 44<title>番号を押したか押していないか画面</title> 45</head> 46 47<body> 48<center> 49 50<?php 51try 52{ 53 54$dsn='mysql:dbname=db;host=???;charset=utf8'; 55$user='user_name'; 56$password='pass'; 57$dbh=new PDO($dsn,$user,$password); 58$dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); 59 60$sql='SELECT MAX(no) as no FROM num WHERE on_off =1'; 61$stmt=$dbh->prepare($sql); 62$stmt->execute(); 63$rec=$stmt->fetch(PDO::FETCH_ASSOC); 64 65$no=$rec['no']; 66print '<a class="example3"><font size="50"><b>'; 67 print $rec['no']; 68print '</b></font></a>'; 69$dbh=null; 70 71 72print 'までの番号を押した<br/><br/>'; 73 74} 75catch (Exception $e) 76{ 77 print '障害発生'; 78 exit(); 79} 80 81?> 82</center> 83 84<?php 85try 86{ 87 88$dsn='mysql:dbname=db;host=???;charset=utf8'; 89$user='user_name'; 90$password='pass'; 91$dbh=new PDO($dsn,$user,$password); 92$dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); 93 94$sql='SELECT no FROM num WHERE on_off ="0" AND no BETWEEN 0 AND '.$no; 95$stmt=$dbh->prepare($sql); 96$stmt->execute(); 97 98 99 100$dbh=null; 101 102print '番号を押していない一覧<br/>'; 103 104print '<table border="0" cellspacing="15">'; 105print '<tr>'; 106 107for($i=1;$i<=300;$i++) { 108 109if ($i % 10==0){ 110 111 112while(true) 113{ 114 $rec=$stmt->fetch(PDO::FETCH_ASSOC); 115 if($rec==false) 116 { 117 break; 118 } 119$i=$rec['no']; 120 print '<td>'; 121print '<a class="example4"><font size="6">'; 122 print $rec['no']; 123print '</font></a>'; 124 print '</td>'; 125 126if ($i % 10==0){ 127print '</tr>'; 128} 129 130} 131} 132} 133 134} 135catch (Exception $e) 136{ 137 print 'まだ番号はない'; 138 exit(); 139} 140 141?> 142</body> 143</html>
num_add.php
1<?php 2 3try 4{ 5 6$on_off=$_GET['on_off']; 7$num=$_GET['num']; 8$on_off=htmlspecialchars($on_off); 9$num=htmlspecialchars($num); 10 11$dsn='mysql:dbname=db;host=???;charset=utf8'; 12$user='user_name'; 13$password='pass'; 14$dbh=new PDO($dsn,$user,$password); 15$dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); 16 17$sql='UPDATE num SET on_off= ? where no = ? '; 18 19$stmt=$dbh->prepare($sql); 20$data[]=$on_off; 21$data[]=$num; 22$stmt->execute($data); 23 24$dbh=null; 25 26header('Location:num.php'); 27 28 29} 30catch (Exception $e) 31{ 32 print '障害発生'; 33 exit(); 34} 35 36?> 37 38 39 40</body> 41</html>
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
Gooleなどで検索した結果、「Cont+F5」はキャッシュクリアしていると分かったのですが、ここからどのようなコードを書いたらいいのかわかりません。
補足
特になし