###前提・実現したいこと
PHPにてテーブル一覧を作成しており、ループで回して一覧表示後に特定の値を持つデータを複数抽出し、テーブル内のそのセルだけ背景色を変えたいと思うのですが、上手くいきません。
###発生している問題・エラーメッセージ
背景色が最初の名前しか背景色が変更されていない状態です。
###対象のコード
test.html <!DOCTYPE html> <html> <head> 省略 </head> <body> <table> <tr> <th>名前</th><th>誕生日</th><th>年齢</th> </tr> <tr> <#LIST#>//PHPにて置き換えしています </tr> </body> </html>
test.php <?php //接続は省略 $query='select * from check_info'; $i = $lines = ""; if ($result = mysqli_query($link, $query)) { $i=0; while ($row = mysqli_fetch_row($result)) { $name[$i] = $row[0]; $birthday[$i] = $row[1]; $age[$i] = $row[2]; if($name[$i] == "未確定"){ $lines .= "<tr><td style='background-color:red;'>".$name[$i]."</td><td>".$birthday[$i]."</td><td>".$age[$i]."</td></tr>\n"; //未確定ならセルの背景色を赤にする } elseif ($name[$i] == "未確定" && $age[$i] == "30"){ $lines .= "<tr><td style='background-color:red;'>".$name[$i]."</td><td>".$birthday[$i]."</td><td style='background-color:red;'>".$age[$i]."</td></tr>\n"; //名前が未確定、年齢が30なら二つのセルの背景色を赤にする } else { $lines .= "<tr><td>".$name[$i]."</td><td>".$birthday[$i]."</td><td>".$age[$i]."</td></tr>\n"; //そうでなければ普通に表示 } $i++; } mysqli_free_result($result); } mysqli_close($link); $fp=fopen('./test.html','r'); while(!feof($fp)) { $html_line=fgets($fp); $lines=str_replace("<#LIST#>",$lines,$html_line2); echo $lines; } fclose($fp); exit(); ?>
###試したこと
年齢もelseifで指定して、複数のカラムを選択して抽出しようとしたら、最初の名前のみ背景色が赤くなりますが、例えば年齢のテーブル背景色が赤くならないです。
elseifの指定や、構文の考え方が間違っているのでしょうか?
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
MAC OS
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/08 00:28
2017/06/08 00:49
2017/06/08 01:04