PHPの素人なので見苦しいコードかもしれませんがよろしくお願い致します。
PHPを使ってMySQLにアクセスして出力させるプログラムを書いているのですが
その際に<li class="0count_li">(2)</li>
<html> <head> <meta charset="utf-8" /> <title>不動産サイト</title> <link rel="stylesheet" type="text/css" href="../common/style.css"/> <style type="text/css"> li.1count_li { color: red; } </style> <!--フォーム完全クリア--> <script> function resetValue(f){ for (var i=0;i<f.length;i++){ if(f[i].type=="text") f[i].value=""; if(f[i].type=="select-one") f[i].selectedIndex=0; if(f[i].type=="checkbox") f[i].checked=false; } } </script> <!--フォーム完全クリアEND--> </head> <body> <div id="main"> <form name="search_form" action="list2.php" method="post" > <input type="hidden" name="cmd" value="search" /> <table> <tr> <th>マンション名</th> <td><input type="text" name="hotel_name" value="<?php print( htmlspecialchars ( $_POST["hotel_name"] ,ENT_QUOTES ) ) ?>" size="20"></td> </tr> <tr> <th>価格帯</th> <td> <input type="text" name="price_min" value="<?php print( htmlspecialchars ( $_POST["price_min"] ,ENT_QUOTES ) ) ?>" size="8"> - <input type="text" name="price_max" value="<?php print( htmlspecialchars ( $_POST["price_max"] ,ENT_QUOTES ) ) ?>" size="8"><br /> </td> </tr> <tr> <th>住所</th> <td><input type="text" name="address" value="<?php print( htmlspecialchars ( $_POST["address"] ,ENT_QUOTES ) ) ?>" size="20"></td> </tr> <tr> <th>名古屋市</th> <td> <?php $dsn = 'mysql:dbname=xxxx;host=xxxxx'; $user = 'xxxx'; $password = 'xxxxxx'; $dbh = new PDO($dsn, $user, $password); $dbh->query('SET NAMES utf-8'); $sql = "SELECT hotels.area_id,area.ward, Count(id) AS cnt FROM hotels INNER JOIN area ON hotels.area_id = area.area_id GROUP BY hotels.area_id"; $condition = array(); $statement = $pdo->prepare( $sql ); $statement->execute( $condition ); $results = $statement->fetchAll(); $i = 0; foreach((array)$results as $result ){ if(($i >= 0)){ echo '<li class="'.$i.'count_li">' . '('.$result['cnt'].')' . '</li>'; } $i++; } ?> //////////以下は質問以外の部分、回答していただく方に全体像がわかりやすいかもしれないので表記します。 以下は外部ファイルの別のSQL文で動きます。 <input type="checkbox" name="area_id[]" value="1" <?php if (isset($_POST['area_id']) and in_array('1',$_POST['area_id'])) print 'checked'; ?>/> 中村区 <input type="checkbox" name="area_id[]" value="2" <?php if (isset($_POST['area_id']) and in_array('2',$_POST['area_id'])) print 'checked'; ?>/> 西区 //省略 </tr> </table> <input type="submit" value="検索" class="Btn-gray button"> <input type="button" value="リセット" class="Btn-reset button" onClick="resetValue(this.form)"> </form> <br> <?php //hotel_name,price_min,price_max,addressの値があれば<h1>検索結果</h1>表示//////////// if(!empty($_POST["hotel_name"]) or !empty($_POST["price_min"]) or !empty( $_POST["price_max"] ) or !empty( $_POST["address"] ) or !empty( $_POST["area_id"] )){ echo "<h1>検索結果</h1>"; } //hotel_name,price_min,price_max,addressの値があれば<h1>検索結果</h1>表示//////////// if(!empty($_POST["hotel_name"]) or !empty($_POST["price_min"]) or !empty( $_POST["price_max"] ) or !empty( $_POST["address"] ) or !empty( $_POST["area_id"] )){ echo "<table border=\"1\" class=\"table_result\">"; /* <tr> <th></th> <th>物件名</th> <th>住所</th> <th>宿泊料金</th> </tr>";*/ } ?> <?php foreach((array)$results as $result ){ ?> <tr> <td><img src="<?php echo($PHOTODIR)."/" ?><?php if (!empty( htmlspecialchars($result["photofilename"], ENT_QUOTES )) ) { print $result["photofilename"] ;} else { print "noimage.jpg" ;}?>" /></td> <td><p class="h_name"><?php print( htmlspecialchars( $result["hotel_name"], ENT_QUOTES ) ); ?></p><br> <p><?php print( htmlspecialchars( $result["pref"], ENT_QUOTES ) ); ?> <?php print( htmlspecialchars( $result["address"], ENT_QUOTES ) ); ?><br> \<?php print( htmlspecialchars( number_format( $result["price"] ), ENT_QUOTES ) ); ?></p> </td> <td></td> <td></td> </tr> <?php } ?> <?php //hotel_name,price_min,price_max,addressの値があれば</table>表示//////////// if(!empty($_POST["hotel_name"]) or !empty($_POST["price_min"]) or !empty( $_POST["price_max"] ) or !empty( $_POST["address"] ) or !empty( $_POST["area_id"] )){ echo "</table>"; } ?> </div> </body> </html> コード
余分な部分が多いと思いますが以下CSS全体です
style.css
/* CSS Document */ body{ background-color:#F9F9F9; font-size:80%; color:#333; padding:30px 0 0 30px; } div,p,ul,li,dl,dt,dd, table,tr,th,td,form, h1,h2,h3,h4,h5,h6{ padding:0; margin:0; } h1{ font-size: 130%; margin:15px 0; padding: 2px 0 2px 3px; border-left:#008000 5px solid; } table { border-collapse: collapse; border-spacing: 0; } input,textarea,select,option { border:#999 1px solid; } table{ border-top:#93C400 1px solid; border-right:#93C400 1px solid; border-left:#93C400 1px solid; } th,td{ padding: 5px 10px; border:#93C400 1px solid; } th{ background:#E9F3CC; font-weight:normal; } td{ background-color: #F8FBEC; } table.table_result p { line-height: 1.8em; } p.h_name { margin-top: -35px; } ul li{ list-style:none; } a img{ border:#CCC 1px solid; } .red{ color:#C00; } .blue{ color:#30F; } ul.check_ul li { float: left; } .green{ color:#030; } span.space1 { margin-left: 13px; } span.space2 { margin-left: 12px; } span.space3 { margin-left: 13px; } span.space4 { margin-left: 2px; } input.button{ text-align:center; font-size:90%; width:50px; margin:10px auto 0; } .Btn-gray { color: #333; border: 1px solid #AAA; cursor: pointer; background: #EEE; padding:3px 12px; } .Btn-reset.button { color: #333; border: 1px solid #AAA; cursor: pointer; background: #EEE; padding: 3px; } .Btn-gray:hover { color: #666; background: #FFF; } #S01 #main{ width:400px; } #S01 form{ text-align:center; } #S01 table{ width:100%; text-align:left; } #S01 table th{ } #S01 table td{ width:65%; } #S01-03 #main{ width:500px; } #S01 p{ padding:0px; margin:20px; } #S01-03 table{ width:90%; text-align:left; margin:20px; } #S02{ width:500px; } #S02 .view dt{ margin-top: -10px; position:relative; bottom:-140px; background-color:#FFF; opacity: 0.6; filter: alpha(opacity=60); font-weight:bold; font-size:90%; padding: 5px; width:490px; text-align:left; z-index:1; } #S02 .view dd{ width:500px; position:absolute; margin-top: -10px; } #S02 .view .text{ position:relative; top:150px; padding: 0 5px; } #S02 .view .text p{ padding: 0 0 10px; } #S02-10 #main{ width:500px; } #S04-04 #main{ width:500px; } #S04-04 p{ padding:0px; margin:20px; } li.1count_li { color: red !important; } li.1count_li {color: red !important;} コード
回答2件
あなたの回答
tips
プレビュー