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

質問編集履歴

1

追記

2016/08/30 03:54

投稿

earnest_gay
earnest_gay

スコア615

title CHANGED
File without changes
body CHANGED
@@ -49,4 +49,245 @@
49
49
  $apartment,
50
50
  $residentialHome
51
51
  ]);
52
+ ```
53
+
54
+
55
+
56
+ 追記
57
+ ```ここに言語を入力
58
+ <?php
59
+
60
+ $dsn = 'mysql:dbname=test;host=localhost;charset=utf8';
61
+ $user = 'root';
62
+ $password = '';
63
+ $option = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
64
+ $pdo = new PDO($dsn, $user, $password, $option);
65
+
66
+
67
+ $sql = "SELECT MIN(rento) as rento FROM articles";
68
+ $minRentos = $pdo->query($sql);
69
+ $minRento=$minRentos->fetch();
70
+
71
+
72
+ $sql = "SELECT MAX(rento) as rento FROM articles";
73
+ $maxRentos = $pdo->query($sql);
74
+ $maxRento=$maxRentos->fetch();
75
+
76
+
77
+
78
+ $limit = filter_input(INPUT_GET,"limit",FILTER_VALIDATE_INT,["options"=>["default"=>10]]);
79
+
80
+ $sql = sprintf("
81
+ SELECT
82
+ a.`id`,
83
+ a.`title`,
84
+ a.`area`,
85
+ a.`buildingtype`,
86
+ a.`floorplan`,
87
+ a.`rento`,
88
+ a.`deposit`,
89
+ a.`keymoney`,
90
+ a.`body`,
91
+ a.`created`,
92
+ a.`modified`,
93
+ c.`companyName`
94
+ FROM articles a
95
+ INNER JOIN users u ON a.`user_id` = u.`id`
96
+ INNER JOIN companys c ON u.`company_id`= c.`id`
97
+ WHERE title LIKE ?
98
+
99
+ AND (( buildingtype LIKE ? ) or ( buildingtype LIKE ? ) or ( buildingtype LIKE ? ))
100
+
101
+ AND( floorplan LIKE ? )
102
+ AND( floorplan LIKE ? )
103
+ AND( floorplan LIKE ? )
104
+ AND( floorplan LIKE ? )
105
+ AND( floorplan LIKE ? )
106
+ AND( floorplan LIKE ? )
107
+ AND( floorplan LIKE ? )
108
+ AND( floorplan LIKE ? )
109
+ AND( floorplan LIKE ? )
110
+ AND( floorplan LIKE ? )
111
+ AND( floorplan LIKE ? )
112
+ AND( floorplan LIKE ? )
113
+ AND( floorplan LIKE ? )
114
+ AND( floorplan LIKE ? )
115
+ AND( floorplan LIKE ? )
116
+
117
+ LIMIT %s",$limit
118
+ );
119
+
120
+ $search = '%'.filter_input(INPUT_GET,"searchs").'%';
121
+ $mansion = '%'.filter_input(INPUT_GET,"mansion").'%';
122
+ $apartment = '%'.filter_input(INPUT_GET,"apartment").'%';
123
+ $residentialHome = '%'.filter_input(INPUT_GET,"residentialHome").'%';
124
+ $madori1 = '%'.filter_input(INPUT_GET,"1R").'%';
125
+ $madori2 = '%'.filter_input(INPUT_GET,"1K").'%';
126
+ $madori3 = '%'.filter_input(INPUT_GET,"1DK").'%';
127
+ $madori4 = '%'.filter_input(INPUT_GET,"1LDK").'%';
128
+ $madori5 = '%'.filter_input(INPUT_GET,"2K").'%';
129
+ $madori6 = '%'.filter_input(INPUT_GET,"2DK").'%';
130
+ $madori7 = '%'.filter_input(INPUT_GET,"2LDK").'%';
131
+ $madori8 = '%'.filter_input(INPUT_GET,"3K").'%';
132
+ $madori9 = '%'.filter_input(INPUT_GET,"3DK").'%';
133
+ $madori10 = '%'.filter_input(INPUT_GET,"3LDK").'%';
134
+ $madori11 = '%'.filter_input(INPUT_GET,"4K").'%';
135
+ $madori12 = '%'.filter_input(INPUT_GET,"4DK").'%';
136
+ $madori13 = '%'.filter_input(INPUT_GET,"4LDK").'%';
137
+ $madori14 = '%'.filter_input(INPUT_GET,"4LDKS").'%';
138
+ $madori15 = '%'.filter_input(INPUT_GET,"5LDK~").'%';
139
+
140
+ $bodys = $pdo->prepare($sql);
141
+ $bodys -> execute([
142
+ $search,
143
+ $mansion,
144
+ $apartment,
145
+ $residentialHome,
146
+ $madori1,
147
+ $madori2,
148
+ $madori3,
149
+ $madori4,
150
+ $madori5,
151
+ $madori6,
152
+ $madori7,
153
+ $madori8,
154
+ $madori9,
155
+ $madori10,
156
+ $madori11,
157
+ $madori12,
158
+ $madori13,
159
+ $madori14,
160
+ $madori15
161
+ ]);
162
+ ?>
163
+
164
+ <!-- ここまで裏の処理 -->
165
+
166
+ <form action="" method="get">
167
+
168
+ 表示件数
169
+ <select name="limit">
170
+ <?php
171
+ for ($i= 5; $i <=50;$i=$i+5){
172
+ $selected = $i == 10 ? 'selected': '';
173
+ echo '<option value="'. $i .'"'. $selected .'> '. $i .'件づつ</option>';
174
+ }
175
+ ?>
176
+ </select>
177
+ <br />
178
+ <br />
179
+
180
+
181
+ フリーワード
182
+ <input type="text" name="searchs">
183
+ <br />
184
+ <br />
185
+
186
+
187
+ 家賃
188
+ <select name="limitMin">
189
+ <?php
190
+ echo '<option value="'.sprintf('%0.1f', 0) .'">下限なし</option><br />';
191
+ $startPrice = round($minRento['rento'],-3)/10000;
192
+ $shredded = 0.5;
193
+ for ($startPrice; $startPrice <= (round($maxRento['rento'],-3)/10000); $startPrice = $startPrice + $shredded) {
194
+ echo '<option value="'.sprintf('%0.1f', $startPrice) .'">'.$startPrice .'万円以上</option><br />';
195
+ }
196
+ ?>
197
+ </select>
198
+
199
+ <select name="limitMax">
200
+ <?php
201
+ $startPrice = round($minRento['rento'],-3)/10000;
202
+ $shredded = 0.5;
203
+ for ($startPrice + $swing; $startPrice <= (round($maxRento['rento'],-3)/10000); $startPrice = $startPrice + $shredded) {
204
+ echo '<option value="'.sprintf('%0.1f', $startPrice) .'">'.$startPrice .'万円以上</option><br />';
205
+ }
206
+ echo '<option value="'.sprintf('%0.1f', 0) .'" selected>上限なし</option><br />';
207
+ ?>
208
+ </select>
209
+ <br />
210
+ <br />
211
+
212
+
213
+ 建物種別
214
+ <input type="checkbox" name="mansion" value="マンション">マンション
215
+ <input type="checkbox" name="apartment" value="アパート">アパート
216
+ <input type="checkbox" name="residentialHome" value="一戸建て">一戸建て・その他
217
+ <br />
218
+ <br />
219
+
220
+
221
+ 間取
222
+ <?php
223
+ $madoris = array(
224
+ '1R',
225
+ '1K',
226
+ '1DK',
227
+ '1LDK',
228
+ '2K',
229
+ '2DK',
230
+ '2LDK',
231
+ '3K',
232
+ '3DK',
233
+ '3LDK',
234
+ '4K',
235
+ '4DK',
236
+ '4LDK',
237
+ '4LDKS',
238
+ '5LDK~',
239
+ );
240
+ ?>
241
+ <?php
242
+
243
+ foreach($madoris as $madori ){
244
+ echo '<input type="checkbox" name="' . $madori . '" value="' . $madori . '">' . $madori . '';
245
+ }
246
+ ?>
247
+ <br />
248
+ <br />
249
+ <input type="submit" name="submit" value="選択した条件で検索する">
250
+ </form>
251
+
252
+
253
+ <table border="" width="100%">
254
+ <thead>
255
+ <tr>
256
+ <th>NO</th>
257
+ <th>タイトル</th>
258
+ <th>概要</th>
259
+ <th>間取</th>
260
+ <th>建物種別</th>
261
+ <th>賃料</th>
262
+ <th>敷金/礼金</th>
263
+ <th>管理会社</th>
264
+ <th>公開日</th>
265
+ </tr>
266
+ </thead>
267
+ <tbody>
268
+ <?php
269
+ foreach($bodys as $body){
270
+ ?>
271
+ <tr>
272
+ <td><?php echo $body['id']; ?></td>
273
+ <td><?php echo $body['title'] ?></td>
274
+ <td><?php echo $body['body'] ?></td>
275
+ <td><?php echo $body['floorplan'] ?></td>
276
+ <td><?php echo $body['buildingtype'] ?></td>
277
+ <td><?php echo number_format($body['rento']) ?></td>
278
+ <td><?php echo sprintf('%.1f', ($body['deposit'] / $body['rento']))."/".sprintf('%0.1f', ($body['keymoney'] / $body['rento'])) ?></td>
279
+
280
+
281
+
282
+ <td><?php echo $body['companyName'] ?></td>
283
+
284
+
285
+
286
+
287
+ <td><?php echo date('Y年m月d日', strtotime($body['created'])); ?></td>
288
+
289
+ </tr>
290
+ <?php } ?>
291
+ </tbody>
292
+ </table>
52
293
  ```