teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

編集しました。

2016/06/01 14:40

投稿

442ky119
442ky119

スコア207

title CHANGED
File without changes
body CHANGED
@@ -118,6 +118,7 @@
118
118
 
119
119
  ```
120
120
 
121
+ ```PHP
121
122
  <form action="hoge.php" form method="REQUEST">
122
123
 
123
124
  <input type="radio" name="city" value="04100">仙台市
@@ -221,4 +222,5 @@
221
222
  $i++;
222
223
  }
223
224
  echo '</table>';
224
- ?>
225
+ ?>
226
+ ```

3

PHPコードを載せます。

2016/06/01 14:40

投稿

442ky119
442ky119

スコア207

title CHANGED
File without changes
body CHANGED
@@ -116,4 +116,109 @@
116
116
  echo '</table>';
117
117
  ?>
118
118
 
119
- ```
119
+ ```
120
+
121
+ <form action="hoge.php" form method="REQUEST">
122
+
123
+ <input type="radio" name="city" value="04100">仙台市
124
+ <input type="radio" name="city" value="04201">石巻市
125
+
126
+
127
+
128
+ <input type="submit" name="submit" value="送信">
129
+ </form>
130
+ </body>
131
+ <?php
132
+ if ( isset($_REQUEST [ 'my_filter' ] ) ) {$area =$_REQUEST [ 'my_filter' ];$my_page=1;
133
+ } else { if( preg_match( '![0-9]{5}!',$_REQUEST[ 'my_filter' ] ){
134
+ $area =$_REQUEST['my_filter'];
135
+ } else {
136
+ $area = '04110';
137
+ } if ( isset( $_REQUEST[ 'my_page' ] ) && is_numeric($_REQUEST[ 'my_page' ] ) ) {
138
+
139
+ $my_page = absint($_REQUEST[ 'my_page' ] );
140
+ } else {
141
+ $my_page = 1;
142
+ }
143
+ }
144
+ $id= '私のid';
145
+ $item_per_page = 100;
146
+ $ct = '01';
147
+ $start = ( $my_page - 1) * $item_per_page + 1;
148
+ $url = 'http://search.olp.yahooapis.jp/OpenLocalPlatform/V1/localSearch?appid=' . $id . '&ac=' . $area .'&gc='. $ct.'&results=' . $item_per_page . '&start=' . $start . '&detail=full';
149
+ $xml = simplexml_load_file( $url );
150
+ $total_count = $xml->ResultInfo->Total;
151
+
152
+ echo '<table class="left">';
153
+ echo '<caption>' . $start . '件目から' . $item_per_page . '件 表示中 / 総件数 ' . $total_count . '</caption>';
154
+
155
+ echo '<style scoped>.paging, table{width:80%;margin:auto;}td{border-bottom:1px solid #ccc;}td{color:#2980b9;}form{text-align:center;padding:2em;}
156
+ .page-link{padding:1em;margin:.3em;display:inline-block;width:3em;border:1px solid #ccc;word-wrap:normal;}h2{text-align:center;margin:2em 0;}</style>';
157
+
158
+ $html = '<tr><td>%1$s</td><td>%2$s</td><td>%3$s</td><td>%4$s</td><td>%5$s</td><td>%6$s</td><td>%7$s</td></tr>';
159
+ $i = 1; function paging($limit, $page, $disp=5){
160
+ global $area;
161
+ //$dispはページ番号の表示数
162
+ $next = $page+1;
163
+ $prev = $page-1;
164
+
165
+ //ページ番号リンク用
166
+ $start = ($page-floor($disp/2) > 0) ? ($page-floor($disp/2)) : 1;//始点
167
+ $end = ($start > 1) ? ($page+floor($disp/2)) : $disp;//終点
168
+ $start = ($limit < $end)? $start-($end-$limit):$start;//始点再計算
169
+
170
+ if($page != 1 ) {
171
+ print '<a href="?my_page='.$prev.'&name='.$area.'">&laquo; 前へ</a>';
172
+ }
173
+
174
+ //最初のページへのリンク
175
+ if($start >= floor($disp/2)){
176
+ print '<a href="?my_page=1&name='.$area.'">1</a>';
177
+ if($start > floor($disp/2)) print "..."; //ドットの表示
178
+ }
179
+
180
+
181
+ for($i=$start; $i <= $end ; $i++){//ページリンク表示ループ
182
+
183
+ $class = ($page == $i) ? ' class="current"':"";//現在地を表すCSSクラス
184
+
185
+ if($i <= $limit && $i > 0 )//1以上最大ページ数以下の場合
186
+ print '<a href="?my_page='.$i.'&name='.$area.'"'.$class.'>'.$i.'</a>';//ページ番号リンク表示
187
+
188
+ }
189
+
190
+ //最後のページへのリンク
191
+ if($limit > $end){
192
+ if($limit-1 > $end ) print "..."; //ドットの表示
193
+ print '<a href="?my_page='.$limit.'&name='.$area.'">'.$limit.'</a>';
194
+ }
195
+
196
+ if($page < $limit){
197
+ print '<a href="?my_page='.$next.'&name='.$area.'">次へ &raquo;</a>';
198
+ }
199
+
200
+ /*確認用
201
+ print "<p>current:".$page."<br>";
202
+ print "next:".$next."<br>";
203
+ print "prev:".$prev."<br>";
204
+ print "limit:".$limit."<br>";
205
+ print "start:".$start."<br>";
206
+ print "end:".$end."</p>";*/
207
+
208
+ }
209
+
210
+ $limit = 10;//最大ページ数
211
+ $page = empty($_REQUEST ["my_page"])? 1:$_REQUEST["my_page"];//ページ番号
212
+
213
+ paging($limit, $page);
214
+
215
+
216
+ foreach ( $xml->Feature as $key => $item ) {
217
+
218
+ printf( $html, $item->Name, $item->Property->Yomi, $item->Property->Tel1, $item->Property->Address, $item->Property->Station->Railway, $item->Property->Station->Name . '駅', $item->Property->Detail->OfficialPcUrl1 );
219
+
220
+
221
+ $i++;
222
+ }
223
+ echo '</table>';
224
+ ?>

2

phpコードを載せます。

2016/06/01 14:38

投稿

442ky119
442ky119

スコア207

title CHANGED
File without changes
body CHANGED
@@ -2,6 +2,7 @@
2
2
  わからない部分は、if(issetの後に何を書けばいいかわかりません。
3
3
  今、美味しいうどんが食べたいみたいに北海道のラジオボタンをクリックしたら北海道のうどんやが表示されるようにしたいのですが詳しいやり方がわかりません。下記にhtmlとphpコードを書きましたが、間違いはありますか?また、htmlとphpのコードの二つはradioForm.phpに書くのですか?
4
4
 
5
+
5
6
  ```html
6
7
 
7
8
  <!doctype html>
@@ -21,21 +22,98 @@
21
22
  <input type="submit" name="submit" value="送信">
22
23
  ```
23
24
 
24
- ```PHP
25
+ ```PHP
25
26
  <?php
26
- if ( isset( $_post[ 'city' ] ) && preg_match( '![0-9]{5}!', $_post[ 'city' ] ) ) {
27
+ if ( isset( $_GET[ 'my_filter' ] ) && preg_match( '![0-9]{5}!', $_GET[ 'my_filter' ] ) ) {
27
- $area = $_GET[ 'city' ];
28
+ $area = $_GET[ 'my_filter' ];
28
- } else {
29
+ } else {
29
- $area = '13';
30
+ $area = '04100';
31
+ }
32
+ if ( isset( $_GET[ 'my_page' ] ) && is_numeric( $_GET[ 'my_page' ] ) ) {
33
+
34
+ $my_page = absint( $_GET[ 'my_page' ] );
35
+ } else {
36
+ $my_page = 1;
37
+ }
38
+
39
+ $id = 'id';
40
+ $item_per_page = 50;
41
+ $start = ( $my_page - 1) * $item_per_page + 1;
42
+ $url = 'http://search.olp.yahooapis.jp/OpenLocalPlatform/V1/localSearch?appid=' . $id . '&ac=' . $area . '&results=' . $item_per_page . '&start=' . $start . '&detail=full';
43
+ $xml = simplexml_load_file( $url );
44
+ $total_count = $xml->ResultInfo->Total;
45
+
46
+ echo '<table class="left">';
47
+ echo '<caption>' . $start . '件目から' . $item_per_page . '件 表示中 / 総件数 ' . $total_count . '</caption>';
48
+ echo '<style scoped>.paging, table{width:80%;margin:auto;}td{border-bottom:1px solid #ccc;}td{color:#2980b9;}form{text-align:center;padding:2em;}
49
+ .page-link{padding:1em;margin:.3em;display:inline-block;width:3em;border:1px solid #ccc;word-wrap:normal;}h2{text-align:center;margin:2em 0;}</style>';
50
+
51
+ $html = '<tr><td>%1$s</td><td>%2$s</td><td>%3$s</td><td>%4$s</td><td>%5$s</td><td>%6$s</td><td>%7$s</td></tr>';
52
+ $i = 1;
53
+
54
+ function paging($limit, $page, $disp=5){
55
+ global $area;
56
+ //$dispはページ番号の表示数
57
+ $next = $page+1;
58
+ $prev = $page-1;
59
+
60
+ //ページ番号リンク用
61
+ $start = ($page-floor($disp/2) > 0) ? ($page-floor($disp/2)) : 1;//始点
62
+ $end = ($start > 1) ? ($page+floor($disp/2)) : $disp;//終点
63
+ $start = ($limit < $end)? $start-($end-$limit):$start;//始点再計算
64
+
65
+ if($page != 1 ) {
66
+ print '<a href="?my_page='.$prev.'&my_filter='.$area.'">&laquo; 前へ</a>';
30
67
  }
68
+
69
+ //最初のページへのリンク
70
+ if($start >= floor($disp/2)){
71
+ print '<a href="?my_page=1&my_filter='.$area.'">1</a>';
72
+ if($start > floor($disp/2)) print "..."; //ドットの表示
73
+ }
74
+
75
+
76
+ for($i=$start; $i <= $end ; $i++){//ページリンク表示ループ
77
+
78
+ $class = ($page == $i) ? ' class="current"':"";//現在地を表すCSSクラス
79
+
80
+ if($i <= $limit && $i > 0 )//1以上最大ページ数以下の場合
81
+ print '<a href="?my_page='.$i.'&my_filter='.$area.'"'.$class.'>'.$i.'</a>';//ページ番号リンク表示
82
+
83
+ }
84
+
85
+ //最後のページへのリンク
86
+ if($limit > $end){
87
+ if($limit-1 > $end ) print "..."; //ドットの表示
88
+ print '<a href="?my_page='.$limit.'&my_filter='.$area.'">'.$limit.'</a>';
89
+ }
90
+
91
+ if($page < $limit){
92
+ print '<a href="?my_page='.$next.'&my_filter='.$area.'">次へ &raquo;</a>';
93
+ }
94
+
95
+ /*確認用
96
+ print "<p>current:".$page."<br>";
97
+ print "next:".$next."<br>";
98
+ print "prev:".$prev."<br>";
99
+ print "limit:".$limit."<br>";
100
+ print "start:".$start."<br>";
101
+ print "end:".$end."</p>";*/
102
+
103
+ }
104
+
105
+ $limit = 10;//最大ページ数
31
- if ( isset( $_GET[ 'my_page' ] ) && is_numeric( $_GET[ 'my_page' ] ) ) {
106
+ $page = empty($_GET["my_page"])? 1:$_GET["my_page"];//ページ番号
107
+
108
+ paging($limit, $page);
32
109
 
33
- $my_page = absint( $_GET[ 'my_page' ] );
110
+ foreach ( $xml->Feature as $key => $item ) {
34
- } else {
35
- $my_page = 1;
36
- }
37
- $id= '私のid';
38
- $item_per_page = 100;
39
- $ct = '01';
40
111
 
112
+ printf( $html, $item->Name, $item->Property->Yomi, $item->Property->Tel1, $item->Property->Address, $item->Property->Station->Railway, $item->Property->Station->Name . '駅', $item->Property->Detail->OfficialPcUrl1 );
113
+
114
+ $i++;
115
+ }
116
+ echo '</table>';
117
+ ?>
118
+
41
119
  ```

1

2016/05/31 08:11

投稿

442ky119
442ky119

スコア207

title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,6 @@
1
1
  題名の通り、ラジオボタンのフォームのデータを受け取る方法が知りたいです。ラジオボタンの送信のhtmlの書き方はわかります。しかし、ラジオボタンの受信のphpの書き方がわかりません。つまりパラメータの渡し方がわかりません。
2
2
  わからない部分は、if(issetの後に何を書けばいいかわかりません。
3
- 今、美味しいうどんが食べたいみたいに北海道のラジオボタンをクリックしたら北海道のうどんやが表示されるようにしたいのですが詳しいやり方がわかりません。下記にhtmlとphpコードを書きましたが、間違いはありますか?
3
+ 今、美味しいうどんが食べたいみたいに北海道のラジオボタンをクリックしたら北海道のうどんやが表示されるようにしたいのですが詳しいやり方がわかりません。下記にhtmlとphpコードを書きましたが、間違いはありますか?また、htmlとphpのコードの二つはradioForm.phpに書くのですか?
4
4
 
5
5
  ```html
6
6