質問編集履歴
4
誤字修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
PHPの素人なので見苦しいコードかもしれませんがよろしくお願い致します。
|
2
2
|
|
3
3
|
PHPを使ってMySQLにアクセスして出力させるプログラムを書いているのですが
|
4
4
|
その際に<li class="0count_li">(2)</li>
|
3
弱冠コードの幅変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -48,18 +48,22 @@
|
|
48
48
|
<table>
|
49
49
|
<tr>
|
50
50
|
<th>マンション名</th>
|
51
|
-
<td><input type="text" name="hotel_name" value="<?php print( htmlspecialchars
|
51
|
+
<td><input type="text" name="hotel_name" value="<?php print( htmlspecialchars
|
52
|
+
( $_POST["hotel_name"] ,ENT_QUOTES ) ) ?>" size="20"></td>
|
52
53
|
</tr>
|
53
54
|
<tr>
|
54
55
|
<th>価格帯</th>
|
55
56
|
<td>
|
56
|
-
<input type="text" name="price_min" value="<?php print( htmlspecialchars
|
57
|
+
<input type="text" name="price_min" value="<?php print( htmlspecialchars
|
58
|
+
( $_POST["price_min"] ,ENT_QUOTES ) ) ?>" size="8"> -
|
57
|
-
<input type="text" name="price_max" value="<?php print( htmlspecialchars
|
59
|
+
<input type="text" name="price_max" value="<?php print( htmlspecialchars
|
60
|
+
( $_POST["price_max"] ,ENT_QUOTES ) ) ?>" size="8"><br />
|
58
61
|
</td>
|
59
62
|
</tr>
|
60
63
|
<tr>
|
61
64
|
<th>住所</th>
|
62
|
-
<td><input type="text" name="address" value="<?php print( htmlspecialchars
|
65
|
+
<td><input type="text" name="address" value="<?php print( htmlspecialchars
|
66
|
+
( $_POST["address"] ,ENT_QUOTES ) ) ?>" size="20"></td>
|
63
67
|
</tr>
|
64
68
|
<tr>
|
65
69
|
<th>名古屋市</th>
|
@@ -113,7 +117,8 @@
|
|
113
117
|
|
114
118
|
//hotel_name,price_min,price_max,addressの値があれば<h1>検索結果</h1>表示////////////
|
115
119
|
|
120
|
+
if(!empty($_POST["hotel_name"]) or !empty($_POST["price_min"]) or
|
116
|
-
|
121
|
+
!empty( $_POST["price_max"] ) or !empty( $_POST["address"] ) or !empty( $_POST["area_id"] )){
|
117
122
|
echo "<h1>検索結果</h1>";
|
118
123
|
}
|
119
124
|
|
2
ご指摘いただいたのでCSS追加致しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,23 +14,370 @@
|
|
14
14
|
ご教授何卒お願いします。
|
15
15
|
|
16
16
|
|
17
|
+
|
18
|
+
|
19
|
+
```<!DOCTYPE html>
|
20
|
+
<html>
|
21
|
+
<head>
|
22
|
+
<meta charset="utf-8" />
|
23
|
+
<title>不動産サイト</title>
|
24
|
+
<link rel="stylesheet" type="text/css" href="../common/style.css"/>
|
25
|
+
<style type="text/css">
|
26
|
+
|
27
|
+
li.1count_li {
|
28
|
+
color: red;
|
29
|
+
}
|
30
|
+
</style>
|
31
|
+
|
32
|
+
<!--フォーム完全クリア-->
|
33
|
+
<script>
|
34
|
+
function resetValue(f){
|
35
|
+
for (var i=0;i<f.length;i++){
|
36
|
+
if(f[i].type=="text") f[i].value="";
|
37
|
+
if(f[i].type=="select-one") f[i].selectedIndex=0;
|
38
|
+
if(f[i].type=="checkbox") f[i].checked=false;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
</script>
|
42
|
+
<!--フォーム完全クリアEND-->
|
43
|
+
</head>
|
44
|
+
<body>
|
45
|
+
<div id="main">
|
46
|
+
<form name="search_form" action="list2.php" method="post" >
|
47
|
+
<input type="hidden" name="cmd" value="search" />
|
48
|
+
<table>
|
49
|
+
<tr>
|
50
|
+
<th>マンション名</th>
|
51
|
+
<td><input type="text" name="hotel_name" value="<?php print( htmlspecialchars( $_POST["hotel_name"] ,ENT_QUOTES ) ) ?>" size="20"></td>
|
52
|
+
</tr>
|
53
|
+
<tr>
|
54
|
+
<th>価格帯</th>
|
55
|
+
<td>
|
56
|
+
<input type="text" name="price_min" value="<?php print( htmlspecialchars( $_POST["price_min"] ,ENT_QUOTES ) ) ?>" size="8"> -
|
57
|
+
<input type="text" name="price_max" value="<?php print( htmlspecialchars( $_POST["price_max"] ,ENT_QUOTES ) ) ?>" size="8"><br />
|
58
|
+
</td>
|
59
|
+
</tr>
|
60
|
+
<tr>
|
61
|
+
<th>住所</th>
|
62
|
+
<td><input type="text" name="address" value="<?php print( htmlspecialchars( $_POST["address"] ,ENT_QUOTES ) ) ?>" size="20"></td>
|
63
|
+
</tr>
|
64
|
+
<tr>
|
65
|
+
<th>名古屋市</th>
|
66
|
+
<td>
|
67
|
+
|
68
|
+
<?php
|
69
|
+
|
17
|
-
$dsn = 'mysql:dbname=
|
70
|
+
$dsn = 'mysql:dbname=xxxx;host=xxxxx';
|
18
|
-
|
71
|
+
$user = 'xxxx';
|
19
|
-
|
72
|
+
$password = 'xxxxxx';
|
20
|
-
|
73
|
+
$dbh = new PDO($dsn, $user, $password);
|
21
|
-
|
74
|
+
$dbh->query('SET NAMES utf-8');
|
22
75
|
$sql = "SELECT hotels.area_id,area.ward, Count(id) AS cnt
|
23
76
|
FROM hotels
|
24
77
|
INNER JOIN area ON hotels.area_id = area.area_id
|
25
78
|
GROUP BY hotels.area_id";
|
26
|
-
|
79
|
+
$condition = array();
|
27
|
-
|
80
|
+
$statement = $pdo->prepare( $sql );
|
28
|
-
|
81
|
+
$statement->execute( $condition );
|
29
|
-
|
82
|
+
$results = $statement->fetchAll();
|
30
83
|
$i = 0;
|
31
84
|
foreach((array)$results as $result ){
|
32
|
-
|
85
|
+
if(($i >= 0)){
|
33
|
-
|
86
|
+
echo '<li class="'.$i.'count_li">' . '('.$result['cnt'].')' . '</li>';
|
34
|
-
|
87
|
+
}
|
35
|
-
|
88
|
+
$i++;
|
36
|
-
}
|
89
|
+
}
|
90
|
+
|
91
|
+
?>
|
92
|
+
|
93
|
+
//////////以下は質問以外の部分、回答していただく方に全体像がわかりやすいかもしれないので表記します。
|
94
|
+
以下は外部ファイルの別のSQL文で動きます。
|
95
|
+
|
96
|
+
<input type="checkbox" name="area_id[]" value="1" <?php if (isset($_POST['area_id']) and in_array('1',$_POST['area_id'])) print 'checked'; ?>/>
|
97
|
+
中村区
|
98
|
+
<input type="checkbox" name="area_id[]" value="2" <?php if (isset($_POST['area_id']) and in_array('2',$_POST['area_id'])) print 'checked'; ?>/>
|
99
|
+
西区
|
100
|
+
|
101
|
+
|
102
|
+
//省略
|
103
|
+
|
104
|
+
|
105
|
+
</tr>
|
106
|
+
|
107
|
+
</table>
|
108
|
+
<input type="submit" value="検索" class="Btn-gray button">
|
109
|
+
<input type="button" value="リセット" class="Btn-reset button" onClick="resetValue(this.form)">
|
110
|
+
</form>
|
111
|
+
<br>
|
112
|
+
<?php
|
113
|
+
|
114
|
+
//hotel_name,price_min,price_max,addressの値があれば<h1>検索結果</h1>表示////////////
|
115
|
+
|
116
|
+
if(!empty($_POST["hotel_name"]) or !empty($_POST["price_min"]) or !empty( $_POST["price_max"] ) or !empty( $_POST["address"] ) or !empty( $_POST["area_id"] )){
|
117
|
+
echo "<h1>検索結果</h1>";
|
118
|
+
}
|
119
|
+
|
120
|
+
//hotel_name,price_min,price_max,addressの値があれば<h1>検索結果</h1>表示////////////
|
121
|
+
if(!empty($_POST["hotel_name"]) or !empty($_POST["price_min"]) or !empty( $_POST["price_max"] ) or !empty( $_POST["address"] ) or !empty( $_POST["area_id"] )){
|
122
|
+
echo "<table border=\"1\" class=\"table_result\">";
|
123
|
+
/* <tr>
|
124
|
+
<th></th>
|
125
|
+
<th>物件名</th>
|
126
|
+
<th>住所</th>
|
127
|
+
<th>宿泊料金</th>
|
128
|
+
</tr>";*/
|
129
|
+
}
|
130
|
+
?>
|
131
|
+
|
132
|
+
<?php
|
133
|
+
foreach((array)$results as $result ){
|
134
|
+
?>
|
135
|
+
<tr>
|
136
|
+
<td><img src="<?php echo($PHOTODIR)."/" ?><?php if (!empty( htmlspecialchars($result["photofilename"], ENT_QUOTES )) ) { print $result["photofilename"] ;}
|
137
|
+
else { print "noimage.jpg" ;}?>" /></td>
|
138
|
+
<td><p class="h_name"><?php print( htmlspecialchars( $result["hotel_name"], ENT_QUOTES ) ); ?></p><br>
|
139
|
+
<p><?php print( htmlspecialchars( $result["pref"], ENT_QUOTES ) ); ?>
|
140
|
+
<?php print( htmlspecialchars( $result["address"], ENT_QUOTES ) ); ?><br>
|
141
|
+
\<?php print( htmlspecialchars( number_format( $result["price"] ), ENT_QUOTES ) ); ?></p>
|
142
|
+
</td>
|
143
|
+
<td></td>
|
144
|
+
<td></td>
|
145
|
+
</tr>
|
146
|
+
<?php
|
147
|
+
}
|
148
|
+
?>
|
149
|
+
<?php
|
150
|
+
//hotel_name,price_min,price_max,addressの値があれば</table>表示////////////
|
151
|
+
if(!empty($_POST["hotel_name"]) or !empty($_POST["price_min"]) or !empty( $_POST["price_max"] ) or !empty( $_POST["address"] ) or !empty( $_POST["area_id"] )){
|
152
|
+
echo "</table>";
|
153
|
+
}
|
154
|
+
?>
|
155
|
+
|
156
|
+
</div>
|
157
|
+
</body>
|
158
|
+
</html>
|
159
|
+
コード
|
160
|
+
```
|
161
|
+
|
162
|
+
余分な部分が多いと思いますが以下CSS全体です
|
163
|
+
style.css
|
164
|
+
|
165
|
+
|
166
|
+
```@charset "utf-8";
|
167
|
+
/* CSS Document */
|
168
|
+
|
169
|
+
body{
|
170
|
+
background-color:#F9F9F9;
|
171
|
+
font-size:80%;
|
172
|
+
color:#333;
|
173
|
+
padding:30px 0 0 30px;
|
174
|
+
}
|
175
|
+
|
176
|
+
div,p,ul,li,dl,dt,dd,
|
177
|
+
table,tr,th,td,form,
|
178
|
+
h1,h2,h3,h4,h5,h6{
|
179
|
+
padding:0;
|
180
|
+
margin:0;
|
181
|
+
}
|
182
|
+
|
183
|
+
h1{
|
184
|
+
font-size: 130%;
|
185
|
+
margin:15px 0;
|
186
|
+
padding: 2px 0 2px 3px;
|
187
|
+
border-left:#008000 5px solid;
|
188
|
+
}
|
189
|
+
|
190
|
+
table {
|
191
|
+
border-collapse: collapse;
|
192
|
+
border-spacing: 0;
|
193
|
+
}
|
194
|
+
|
195
|
+
input,textarea,select,option {
|
196
|
+
border:#999 1px solid;
|
197
|
+
}
|
198
|
+
|
199
|
+
table{
|
200
|
+
border-top:#93C400 1px solid;
|
201
|
+
border-right:#93C400 1px solid;
|
202
|
+
border-left:#93C400 1px solid;
|
203
|
+
}
|
204
|
+
|
205
|
+
th,td{
|
206
|
+
padding: 5px 10px;
|
207
|
+
border:#93C400 1px solid;
|
208
|
+
}
|
209
|
+
|
210
|
+
th{
|
211
|
+
background:#E9F3CC;
|
212
|
+
font-weight:normal;
|
213
|
+
}
|
214
|
+
|
215
|
+
td{
|
216
|
+
background-color: #F8FBEC;
|
217
|
+
}
|
218
|
+
|
219
|
+
table.table_result p {
|
220
|
+
line-height: 1.8em;
|
221
|
+
}
|
222
|
+
|
223
|
+
p.h_name {
|
224
|
+
margin-top: -35px;
|
225
|
+
}
|
226
|
+
|
227
|
+
ul li{
|
228
|
+
list-style:none;
|
229
|
+
}
|
230
|
+
|
231
|
+
a img{
|
232
|
+
border:#CCC 1px solid;
|
233
|
+
}
|
234
|
+
|
235
|
+
.red{
|
236
|
+
color:#C00;
|
237
|
+
}
|
238
|
+
|
239
|
+
.blue{
|
240
|
+
color:#30F;
|
241
|
+
}
|
242
|
+
|
243
|
+
ul.check_ul li {
|
244
|
+
float: left;
|
245
|
+
}
|
246
|
+
.green{
|
247
|
+
color:#030;
|
248
|
+
}
|
249
|
+
span.space1 {
|
250
|
+
margin-left: 13px;
|
251
|
+
}
|
252
|
+
span.space2 {
|
253
|
+
margin-left: 12px;
|
254
|
+
}
|
255
|
+
|
256
|
+
span.space3 {
|
257
|
+
margin-left: 13px;
|
258
|
+
}
|
259
|
+
span.space4 {
|
260
|
+
margin-left: 2px;
|
261
|
+
}
|
262
|
+
input.button{
|
263
|
+
text-align:center;
|
264
|
+
font-size:90%;
|
265
|
+
width:50px;
|
266
|
+
margin:10px auto 0;
|
267
|
+
}
|
268
|
+
|
269
|
+
.Btn-gray {
|
270
|
+
color: #333;
|
271
|
+
border: 1px solid #AAA;
|
272
|
+
cursor: pointer;
|
273
|
+
background: #EEE;
|
274
|
+
padding:3px 12px;
|
275
|
+
}
|
276
|
+
|
277
|
+
.Btn-reset.button {
|
278
|
+
color: #333;
|
279
|
+
border: 1px solid #AAA;
|
280
|
+
cursor: pointer;
|
281
|
+
background: #EEE;
|
282
|
+
padding: 3px;
|
283
|
+
}
|
284
|
+
.Btn-gray:hover {
|
285
|
+
color: #666;
|
286
|
+
background: #FFF;
|
287
|
+
}
|
288
|
+
|
289
|
+
|
290
|
+
#S01 #main{
|
291
|
+
width:400px;
|
292
|
+
}
|
293
|
+
#S01 form{
|
294
|
+
text-align:center;
|
295
|
+
}
|
296
|
+
|
297
|
+
#S01 table{
|
298
|
+
width:100%;
|
299
|
+
text-align:left;
|
300
|
+
}
|
301
|
+
|
302
|
+
#S01 table th{
|
303
|
+
}
|
304
|
+
|
305
|
+
#S01 table td{
|
306
|
+
width:65%;
|
307
|
+
}
|
308
|
+
|
309
|
+
#S01-03 #main{
|
310
|
+
width:500px;
|
311
|
+
}
|
312
|
+
|
313
|
+
#S01 p{
|
314
|
+
padding:0px;
|
315
|
+
margin:20px;
|
316
|
+
}
|
317
|
+
|
318
|
+
#S01-03 table{
|
319
|
+
width:90%;
|
320
|
+
text-align:left;
|
321
|
+
margin:20px;
|
322
|
+
}
|
323
|
+
|
324
|
+
|
325
|
+
#S02{
|
326
|
+
width:500px;
|
327
|
+
}
|
328
|
+
|
329
|
+
#S02 .view dt{
|
330
|
+
margin-top: -10px;
|
331
|
+
position:relative;
|
332
|
+
bottom:-140px;
|
333
|
+
background-color:#FFF;
|
334
|
+
opacity: 0.6;
|
335
|
+
filter: alpha(opacity=60);
|
336
|
+
font-weight:bold;
|
337
|
+
font-size:90%;
|
338
|
+
padding: 5px;
|
339
|
+
width:490px;
|
340
|
+
text-align:left;
|
341
|
+
z-index:1;
|
342
|
+
}
|
343
|
+
|
344
|
+
#S02 .view dd{
|
345
|
+
width:500px;
|
346
|
+
position:absolute;
|
347
|
+
margin-top: -10px;
|
348
|
+
}
|
349
|
+
|
350
|
+
#S02 .view .text{
|
351
|
+
position:relative;
|
352
|
+
top:150px;
|
353
|
+
padding: 0 5px;
|
354
|
+
}
|
355
|
+
|
356
|
+
#S02 .view .text p{
|
357
|
+
padding: 0 0 10px;
|
358
|
+
}
|
359
|
+
|
360
|
+
#S02-10 #main{
|
361
|
+
width:500px;
|
362
|
+
}
|
363
|
+
|
364
|
+
#S04-04 #main{
|
365
|
+
width:500px;
|
366
|
+
}
|
367
|
+
|
368
|
+
#S04-04 p{
|
369
|
+
padding:0px;
|
370
|
+
margin:20px;
|
371
|
+
}
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
li.1count_li {
|
376
|
+
color: red !important;
|
377
|
+
}
|
378
|
+
li.1count_li {color: red !important;}
|
379
|
+
|
380
|
+
|
381
|
+
|
382
|
+
コード
|
383
|
+
```
|
1
タイトル変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
CSSが <li class="1count_li">(5)</li> に適用されない(質問変更致しました)
|
body
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
PHPの素人なので見苦しいコードかもしれませんがよろしくお願い致します。
|
1
|
+
> 引用テキストPHPの素人なので見苦しいコードかもしれませんがよろしくお願い致します。
|
2
2
|
|
3
3
|
PHPを使ってMySQLにアクセスして出力させるプログラムを書いているのですが
|
4
4
|
その際に<li class="0count_li">(2)</li>
|