質問編集履歴

4

誤字修正

2016/04/03 13:29

投稿

pechiper
pechiper

スコア17

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- > 引用テキストPHPの素人なので見苦しいコードかもしれませんがよろしくお願い致します。
1
+ PHPの素人なので見苦しいコードかもしれませんがよろしくお願い致します。
2
2
 
3
3
 
4
4
 

3

弱冠コードの幅変更

2016/04/03 13:29

投稿

pechiper
pechiper

スコア17

test CHANGED
File without changes
test CHANGED
@@ -98,7 +98,9 @@
98
98
 
99
99
  <th>マンション名</th>
100
100
 
101
- <td><input type="text" name="hotel_name" value="<?php print( htmlspecialchars( $_POST["hotel_name"] ,ENT_QUOTES ) ) ?>" size="20"></td>
101
+ <td><input type="text" name="hotel_name" value="<?php print( htmlspecialchars
102
+
103
+ ( $_POST["hotel_name"] ,ENT_QUOTES ) ) ?>" size="20"></td>
102
104
 
103
105
  </tr>
104
106
 
@@ -108,9 +110,13 @@
108
110
 
109
111
  <td>
110
112
 
111
- <input type="text" name="price_min" value="<?php print( htmlspecialchars( $_POST["price_min"] ,ENT_QUOTES ) ) ?>" size="8"> -
113
+ <input type="text" name="price_min" value="<?php print( htmlspecialchars
114
+
112
-
115
+ ( $_POST["price_min"] ,ENT_QUOTES ) ) ?>" size="8"> -
116
+
113
- <input type="text" name="price_max" value="<?php print( htmlspecialchars( $_POST["price_max"] ,ENT_QUOTES ) ) ?>" size="8"><br />
117
+ <input type="text" name="price_max" value="<?php print( htmlspecialchars
118
+
119
+ ( $_POST["price_max"] ,ENT_QUOTES ) ) ?>" size="8"><br />
114
120
 
115
121
  </td>
116
122
 
@@ -120,7 +126,9 @@
120
126
 
121
127
  <th>住所</th>
122
128
 
123
- <td><input type="text" name="address" value="<?php print( htmlspecialchars( $_POST["address"] ,ENT_QUOTES ) ) ?>" size="20"></td>
129
+ <td><input type="text" name="address" value="<?php print( htmlspecialchars
130
+
131
+ ( $_POST["address"] ,ENT_QUOTES ) ) ?>" size="20"></td>
124
132
 
125
133
  </tr>
126
134
 
@@ -228,31 +236,81 @@
228
236
 
229
237
 
230
238
 
239
+ if(!empty($_POST["hotel_name"]) or !empty($_POST["price_min"]) or
240
+
241
+ !empty( $_POST["price_max"] ) or !empty( $_POST["address"] ) or !empty( $_POST["area_id"] )){
242
+
243
+ echo "<h1>検索結果</h1>";
244
+
245
+ }
246
+
247
+
248
+
249
+ //hotel_name,price_min,price_max,addressの値があれば<h1>検索結果</h1>表示////////////
250
+
231
251
  if(!empty($_POST["hotel_name"]) or !empty($_POST["price_min"]) or !empty( $_POST["price_max"] ) or !empty( $_POST["address"] ) or !empty( $_POST["area_id"] )){
232
252
 
253
+ echo "<table border=\"1\" class=\"table_result\">";
254
+
255
+ /* <tr>
256
+
257
+ <th></th>
258
+
259
+ <th>物件名</th>
260
+
261
+ <th>住所</th>
262
+
233
- echo "<h1>検索結果</h1>";
263
+ <th>宿泊料金</th>
264
+
234
-
265
+ </tr>";*/
266
+
235
- }
267
+ }
268
+
236
-
269
+ ?>
270
+
271
+
272
+
237
-
273
+ <?php
274
+
238
-
275
+ foreach((array)$results as $result ){
276
+
277
+ ?>
278
+
279
+ <tr>
280
+
281
+ <td><img src="<?php echo($PHOTODIR)."/" ?><?php if (!empty( htmlspecialchars($result["photofilename"], ENT_QUOTES )) ) { print $result["photofilename"] ;}
282
+
283
+ else { print "noimage.jpg" ;}?>" /></td>
284
+
285
+ <td><p class="h_name"><?php print( htmlspecialchars( $result["hotel_name"], ENT_QUOTES ) ); ?></p><br>
286
+
287
+ <p><?php print( htmlspecialchars( $result["pref"], ENT_QUOTES ) ); ?>
288
+
289
+ <?php print( htmlspecialchars( $result["address"], ENT_QUOTES ) ); ?><br>
290
+
291
+ \<?php print( htmlspecialchars( number_format( $result["price"] ), ENT_QUOTES ) ); ?></p>
292
+
293
+ </td>
294
+
295
+ <td></td>
296
+
297
+ <td></td>
298
+
299
+ </tr>
300
+
301
+ <?php
302
+
303
+ }
304
+
305
+ ?>
306
+
307
+ <?php
308
+
239
- //hotel_name,price_min,price_max,addressの値があれば<h1>検索結果</h1>表示////////////
309
+ //hotel_name,price_min,price_max,addressの値があれば</table>表示////////////
240
310
 
241
311
  if(!empty($_POST["hotel_name"]) or !empty($_POST["price_min"]) or !empty( $_POST["price_max"] ) or !empty( $_POST["address"] ) or !empty( $_POST["area_id"] )){
242
312
 
243
- echo "<table border=\"1\" class=\"table_result\">";
244
-
245
- /* <tr>
246
-
247
- <th></th>
313
+ echo "</table>";
248
-
249
- <th>物件名</th>
250
-
251
- <th>住所</th>
252
-
253
- <th>宿泊料金</th>
254
-
255
- </tr>";*/
256
314
 
257
315
  }
258
316
 
@@ -260,54 +318,6 @@
260
318
 
261
319
 
262
320
 
263
- <?php
264
-
265
- foreach((array)$results as $result ){
266
-
267
- ?>
268
-
269
- <tr>
270
-
271
- <td><img src="<?php echo($PHOTODIR)."/" ?><?php if (!empty( htmlspecialchars($result["photofilename"], ENT_QUOTES )) ) { print $result["photofilename"] ;}
272
-
273
- else { print "noimage.jpg" ;}?>" /></td>
274
-
275
- <td><p class="h_name"><?php print( htmlspecialchars( $result["hotel_name"], ENT_QUOTES ) ); ?></p><br>
276
-
277
- <p><?php print( htmlspecialchars( $result["pref"], ENT_QUOTES ) ); ?>
278
-
279
- <?php print( htmlspecialchars( $result["address"], ENT_QUOTES ) ); ?><br>
280
-
281
- \<?php print( htmlspecialchars( number_format( $result["price"] ), ENT_QUOTES ) ); ?></p>
282
-
283
- </td>
284
-
285
- <td></td>
286
-
287
- <td></td>
288
-
289
- </tr>
290
-
291
- <?php
292
-
293
- }
294
-
295
- ?>
296
-
297
- <?php
298
-
299
- //hotel_name,price_min,price_max,addressの値があれば</table>表示////////////
300
-
301
- if(!empty($_POST["hotel_name"]) or !empty($_POST["price_min"]) or !empty( $_POST["price_max"] ) or !empty( $_POST["address"] ) or !empty( $_POST["area_id"] )){
302
-
303
- echo "</table>";
304
-
305
- }
306
-
307
- ?>
308
-
309
-
310
-
311
321
  </div>
312
322
 
313
323
  </body>

2

ご指摘いただいたのでCSS追加致しました。

2016/04/03 13:26

投稿

pechiper
pechiper

スコア17

test CHANGED
File without changes
test CHANGED
@@ -30,15 +30,121 @@
30
30
 
31
31
 
32
32
 
33
+
34
+
35
+
36
+
37
+ ```<!DOCTYPE html>
38
+
39
+ <html>
40
+
41
+ <head>
42
+
43
+ <meta charset="utf-8" />
44
+
45
+ <title>不動産サイト</title>
46
+
47
+ <link rel="stylesheet" type="text/css" href="../common/style.css"/>
48
+
49
+ <style type="text/css">
50
+
51
+
52
+
53
+ li.1count_li {
54
+
55
+ color: red;
56
+
57
+ }
58
+
59
+ </style>
60
+
61
+
62
+
63
+ <!--フォーム完全クリア-->
64
+
65
+ <script>
66
+
67
+ function resetValue(f){
68
+
69
+ for (var i=0;i<f.length;i++){
70
+
71
+ if(f[i].type=="text") f[i].value="";
72
+
73
+ if(f[i].type=="select-one") f[i].selectedIndex=0;
74
+
75
+ if(f[i].type=="checkbox") f[i].checked=false;
76
+
77
+ }
78
+
79
+ }
80
+
81
+ </script>
82
+
83
+ <!--フォーム完全クリアEND-->
84
+
85
+ </head>
86
+
87
+ <body>
88
+
89
+ <div id="main">
90
+
91
+ <form name="search_form" action="list2.php" method="post" >
92
+
93
+ <input type="hidden" name="cmd" value="search" />
94
+
95
+ <table>
96
+
97
+ <tr>
98
+
99
+ <th>マンション名</th>
100
+
101
+ <td><input type="text" name="hotel_name" value="<?php print( htmlspecialchars( $_POST["hotel_name"] ,ENT_QUOTES ) ) ?>" size="20"></td>
102
+
103
+ </tr>
104
+
105
+ <tr>
106
+
107
+ <th>価格帯</th>
108
+
109
+ <td>
110
+
111
+ <input type="text" name="price_min" value="<?php print( htmlspecialchars( $_POST["price_min"] ,ENT_QUOTES ) ) ?>" size="8"> -
112
+
113
+ <input type="text" name="price_max" value="<?php print( htmlspecialchars( $_POST["price_max"] ,ENT_QUOTES ) ) ?>" size="8"><br />
114
+
115
+ </td>
116
+
117
+ </tr>
118
+
119
+ <tr>
120
+
121
+ <th>住所</th>
122
+
123
+ <td><input type="text" name="address" value="<?php print( htmlspecialchars( $_POST["address"] ,ENT_QUOTES ) ) ?>" size="20"></td>
124
+
125
+ </tr>
126
+
127
+ <tr>
128
+
129
+ <th>名古屋市</th>
130
+
131
+ <td>
132
+
133
+
134
+
135
+ <?php
136
+
137
+
138
+
33
- $dsn = 'mysql:dbname=hotel_reservation;host=localhost';
139
+ $dsn = 'mysql:dbname=xxxx;host=xxxxx';
34
-
140
+
35
- $user = 'xxx';
141
+ $user = 'xxxx';
36
-
142
+
37
- $password = 'xxxxxxxxxx';
143
+ $password = 'xxxxxx';
38
-
144
+
39
- $dbh = new PDO($dsn, $user, $password);
145
+ $dbh = new PDO($dsn, $user, $password);
40
-
146
+
41
- $dbh->query('SET NAMES utf-8');
147
+ $dbh->query('SET NAMES utf-8');
42
148
 
43
149
  $sql = "SELECT hotels.area_id,area.ward, Count(id) AS cnt
44
150
 
@@ -48,24 +154,612 @@
48
154
 
49
155
  GROUP BY hotels.area_id";
50
156
 
51
- $condition = array();
157
+ $condition = array();
52
-
158
+
53
- $statement = $pdo->prepare( $sql );
159
+ $statement = $pdo->prepare( $sql );
54
-
160
+
55
- $statement->execute( $condition );
161
+ $statement->execute( $condition );
56
-
162
+
57
- $results = $statement->fetchAll();
163
+ $results = $statement->fetchAll();
58
164
 
59
165
  $i = 0;
60
166
 
61
167
  foreach((array)$results as $result ){
62
168
 
63
- if(($i >= 0)){
64
-
65
- echo '<li class="'.$i.'count_li">' . '('.$result['cnt'].')' . '</li>';
66
-
67
- }
68
-
69
- $i++;
70
-
71
- }
169
+ if(($i >= 0)){
170
+
171
+ echo '<li class="'.$i.'count_li">' . '('.$result['cnt'].')' . '</li>';
172
+
173
+ }
174
+
175
+ $i++;
176
+
177
+ }
178
+
179
+
180
+
181
+ ?>
182
+
183
+
184
+
185
+ //////////以下は質問以外の部分、回答していただく方に全体像がわかりやすいかもしれないので表記します。
186
+
187
+ 以下は外部ファイルの別のSQL文で動きます。
188
+
189
+
190
+
191
+ <input type="checkbox" name="area_id[]" value="1" <?php if (isset($_POST['area_id']) and in_array('1',$_POST['area_id'])) print 'checked'; ?>/>
192
+
193
+ 中村区
194
+
195
+ <input type="checkbox" name="area_id[]" value="2" <?php if (isset($_POST['area_id']) and in_array('2',$_POST['area_id'])) print 'checked'; ?>/>
196
+
197
+ 西区
198
+
199
+
200
+
201
+
202
+
203
+ //省略
204
+
205
+
206
+
207
+
208
+
209
+ </tr>
210
+
211
+
212
+
213
+ </table>
214
+
215
+ <input type="submit" value="検索" class="Btn-gray button">
216
+
217
+ <input type="button" value="リセット" class="Btn-reset button" onClick="resetValue(this.form)">
218
+
219
+ </form>
220
+
221
+ <br>
222
+
223
+ <?php
224
+
225
+
226
+
227
+ //hotel_name,price_min,price_max,addressの値があれば<h1>検索結果</h1>表示////////////
228
+
229
+
230
+
231
+ if(!empty($_POST["hotel_name"]) or !empty($_POST["price_min"]) or !empty( $_POST["price_max"] ) or !empty( $_POST["address"] ) or !empty( $_POST["area_id"] )){
232
+
233
+ echo "<h1>検索結果</h1>";
234
+
235
+ }
236
+
237
+
238
+
239
+ //hotel_name,price_min,price_max,addressの値があれば<h1>検索結果</h1>表示////////////
240
+
241
+ if(!empty($_POST["hotel_name"]) or !empty($_POST["price_min"]) or !empty( $_POST["price_max"] ) or !empty( $_POST["address"] ) or !empty( $_POST["area_id"] )){
242
+
243
+ echo "<table border=\"1\" class=\"table_result\">";
244
+
245
+ /* <tr>
246
+
247
+ <th></th>
248
+
249
+ <th>物件名</th>
250
+
251
+ <th>住所</th>
252
+
253
+ <th>宿泊料金</th>
254
+
255
+ </tr>";*/
256
+
257
+ }
258
+
259
+ ?>
260
+
261
+
262
+
263
+ <?php
264
+
265
+ foreach((array)$results as $result ){
266
+
267
+ ?>
268
+
269
+ <tr>
270
+
271
+ <td><img src="<?php echo($PHOTODIR)."/" ?><?php if (!empty( htmlspecialchars($result["photofilename"], ENT_QUOTES )) ) { print $result["photofilename"] ;}
272
+
273
+ else { print "noimage.jpg" ;}?>" /></td>
274
+
275
+ <td><p class="h_name"><?php print( htmlspecialchars( $result["hotel_name"], ENT_QUOTES ) ); ?></p><br>
276
+
277
+ <p><?php print( htmlspecialchars( $result["pref"], ENT_QUOTES ) ); ?>
278
+
279
+ <?php print( htmlspecialchars( $result["address"], ENT_QUOTES ) ); ?><br>
280
+
281
+ \<?php print( htmlspecialchars( number_format( $result["price"] ), ENT_QUOTES ) ); ?></p>
282
+
283
+ </td>
284
+
285
+ <td></td>
286
+
287
+ <td></td>
288
+
289
+ </tr>
290
+
291
+ <?php
292
+
293
+ }
294
+
295
+ ?>
296
+
297
+ <?php
298
+
299
+ //hotel_name,price_min,price_max,addressの値があれば</table>表示////////////
300
+
301
+ if(!empty($_POST["hotel_name"]) or !empty($_POST["price_min"]) or !empty( $_POST["price_max"] ) or !empty( $_POST["address"] ) or !empty( $_POST["area_id"] )){
302
+
303
+ echo "</table>";
304
+
305
+ }
306
+
307
+ ?>
308
+
309
+
310
+
311
+ </div>
312
+
313
+ </body>
314
+
315
+ </html>
316
+
317
+ コード
318
+
319
+ ```
320
+
321
+
322
+
323
+ 余分な部分が多いと思いますが以下CSS全体です
324
+
325
+ style.css
326
+
327
+
328
+
329
+
330
+
331
+ ```@charset "utf-8";
332
+
333
+ /* CSS Document */
334
+
335
+
336
+
337
+ body{
338
+
339
+ background-color:#F9F9F9;
340
+
341
+ font-size:80%;
342
+
343
+ color:#333;
344
+
345
+ padding:30px 0 0 30px;
346
+
347
+ }
348
+
349
+
350
+
351
+ div,p,ul,li,dl,dt,dd,
352
+
353
+ table,tr,th,td,form,
354
+
355
+ h1,h2,h3,h4,h5,h6{
356
+
357
+ padding:0;
358
+
359
+ margin:0;
360
+
361
+ }
362
+
363
+
364
+
365
+ h1{
366
+
367
+ font-size: 130%;
368
+
369
+ margin:15px 0;
370
+
371
+ padding: 2px 0 2px 3px;
372
+
373
+ border-left:#008000 5px solid;
374
+
375
+ }
376
+
377
+
378
+
379
+ table {
380
+
381
+ border-collapse: collapse;
382
+
383
+ border-spacing: 0;
384
+
385
+ }
386
+
387
+
388
+
389
+ input,textarea,select,option {
390
+
391
+ border:#999 1px solid;
392
+
393
+ }
394
+
395
+
396
+
397
+ table{
398
+
399
+ border-top:#93C400 1px solid;
400
+
401
+ border-right:#93C400 1px solid;
402
+
403
+ border-left:#93C400 1px solid;
404
+
405
+ }
406
+
407
+
408
+
409
+ th,td{
410
+
411
+ padding: 5px 10px;
412
+
413
+ border:#93C400 1px solid;
414
+
415
+ }
416
+
417
+
418
+
419
+ th{
420
+
421
+ background:#E9F3CC;
422
+
423
+ font-weight:normal;
424
+
425
+ }
426
+
427
+
428
+
429
+ td{
430
+
431
+ background-color: #F8FBEC;
432
+
433
+ }
434
+
435
+
436
+
437
+ table.table_result p {
438
+
439
+ line-height: 1.8em;
440
+
441
+ }
442
+
443
+
444
+
445
+ p.h_name {
446
+
447
+ margin-top: -35px;
448
+
449
+ }
450
+
451
+
452
+
453
+ ul li{
454
+
455
+ list-style:none;
456
+
457
+ }
458
+
459
+
460
+
461
+ a img{
462
+
463
+ border:#CCC 1px solid;
464
+
465
+ }
466
+
467
+
468
+
469
+ .red{
470
+
471
+ color:#C00;
472
+
473
+ }
474
+
475
+
476
+
477
+ .blue{
478
+
479
+ color:#30F;
480
+
481
+ }
482
+
483
+
484
+
485
+ ul.check_ul li {
486
+
487
+ float: left;
488
+
489
+ }
490
+
491
+ .green{
492
+
493
+ color:#030;
494
+
495
+ }
496
+
497
+ span.space1 {
498
+
499
+ margin-left: 13px;
500
+
501
+ }
502
+
503
+ span.space2 {
504
+
505
+ margin-left: 12px;
506
+
507
+ }
508
+
509
+
510
+
511
+ span.space3 {
512
+
513
+ margin-left: 13px;
514
+
515
+ }
516
+
517
+ span.space4 {
518
+
519
+ margin-left: 2px;
520
+
521
+ }
522
+
523
+ input.button{
524
+
525
+ text-align:center;
526
+
527
+ font-size:90%;
528
+
529
+ width:50px;
530
+
531
+ margin:10px auto 0;
532
+
533
+ }
534
+
535
+
536
+
537
+ .Btn-gray {
538
+
539
+ color: #333;
540
+
541
+ border: 1px solid #AAA;
542
+
543
+ cursor: pointer;
544
+
545
+ background: #EEE;
546
+
547
+ padding:3px 12px;
548
+
549
+ }
550
+
551
+
552
+
553
+ .Btn-reset.button {
554
+
555
+ color: #333;
556
+
557
+ border: 1px solid #AAA;
558
+
559
+ cursor: pointer;
560
+
561
+ background: #EEE;
562
+
563
+ padding: 3px;
564
+
565
+ }
566
+
567
+ .Btn-gray:hover {
568
+
569
+ color: #666;
570
+
571
+ background: #FFF;
572
+
573
+ }
574
+
575
+
576
+
577
+
578
+
579
+ #S01 #main{
580
+
581
+ width:400px;
582
+
583
+ }
584
+
585
+ #S01 form{
586
+
587
+ text-align:center;
588
+
589
+ }
590
+
591
+
592
+
593
+ #S01 table{
594
+
595
+ width:100%;
596
+
597
+ text-align:left;
598
+
599
+ }
600
+
601
+
602
+
603
+ #S01 table th{
604
+
605
+ }
606
+
607
+
608
+
609
+ #S01 table td{
610
+
611
+ width:65%;
612
+
613
+ }
614
+
615
+
616
+
617
+ #S01-03 #main{
618
+
619
+ width:500px;
620
+
621
+ }
622
+
623
+
624
+
625
+ #S01 p{
626
+
627
+ padding:0px;
628
+
629
+ margin:20px;
630
+
631
+ }
632
+
633
+
634
+
635
+ #S01-03 table{
636
+
637
+ width:90%;
638
+
639
+ text-align:left;
640
+
641
+ margin:20px;
642
+
643
+ }
644
+
645
+
646
+
647
+
648
+
649
+ #S02{
650
+
651
+ width:500px;
652
+
653
+ }
654
+
655
+
656
+
657
+ #S02 .view dt{
658
+
659
+ margin-top: -10px;
660
+
661
+ position:relative;
662
+
663
+ bottom:-140px;
664
+
665
+ background-color:#FFF;
666
+
667
+ opacity: 0.6;
668
+
669
+ filter: alpha(opacity=60);
670
+
671
+ font-weight:bold;
672
+
673
+ font-size:90%;
674
+
675
+ padding: 5px;
676
+
677
+ width:490px;
678
+
679
+ text-align:left;
680
+
681
+ z-index:1;
682
+
683
+ }
684
+
685
+
686
+
687
+ #S02 .view dd{
688
+
689
+ width:500px;
690
+
691
+ position:absolute;
692
+
693
+ margin-top: -10px;
694
+
695
+ }
696
+
697
+
698
+
699
+ #S02 .view .text{
700
+
701
+ position:relative;
702
+
703
+ top:150px;
704
+
705
+ padding: 0 5px;
706
+
707
+ }
708
+
709
+
710
+
711
+ #S02 .view .text p{
712
+
713
+ padding: 0 0 10px;
714
+
715
+ }
716
+
717
+
718
+
719
+ #S02-10 #main{
720
+
721
+ width:500px;
722
+
723
+ }
724
+
725
+
726
+
727
+ #S04-04 #main{
728
+
729
+ width:500px;
730
+
731
+ }
732
+
733
+
734
+
735
+ #S04-04 p{
736
+
737
+ padding:0px;
738
+
739
+ margin:20px;
740
+
741
+ }
742
+
743
+
744
+
745
+
746
+
747
+
748
+
749
+ li.1count_li {
750
+
751
+ color: red !important;
752
+
753
+ }
754
+
755
+ li.1count_li {color: red !important;}
756
+
757
+
758
+
759
+
760
+
761
+
762
+
763
+ コード
764
+
765
+ ```

1

タイトル変更

2016/04/03 13:18

投稿

pechiper
pechiper

スコア17

test CHANGED
@@ -1 +1 @@
1
- PHPを使ってMySQLにアクセスしてCSSclass設定て出力させる
1
+ CSSが <li class="1count_li">(5)</li> に適用されない(質問変更致ました)
test CHANGED
@@ -1,4 +1,4 @@
1
- PHPの素人なので見苦しいコードかもしれませんがよろしくお願い致します。
1
+ > 引用テキストPHPの素人なので見苦しいコードかもしれませんがよろしくお願い致します。
2
2
 
3
3
 
4
4