ページ上部の 1 つのテーブルにチーム メンバーとその情報のリストを表示し、それぞれの行の 1 つのセル内の値に基づいてチームに分割したいと考えています。
「メンバー」テーブルは次のようになります。
+------+------------------------+------------------+
| name | interests | email |
+------+------------------------+------------------+
| John | Golf, Hockey, Baseball | John@example.com |
| Fred | Hockey | Fred@example.com |
+------+------------------------+------------------+
これが私のコードの簡略版です:
$result = mysql_query("SELECT * FROM members");
while($row = mysql_fetch_array($result)){
echo "$row['name'] . $row['interests'] . $row['email']"
}
while($row = mysql_fetch_array($result)){
$sport = array($row['interests']);
if (in_array("Golf", $sport)) {
echo "$row['name'] . $row['email']"
}
if (in_array("Hockey", $sport)) {
echo "$row['name'] . $row['email']"
}
if (in_array("Baseball", $sport)) {
echo "$row['name'] . $row['email']"
}
ページを次のように表示するにはどうすればよいですか?:
全員
名前: ジョン
興味のあること: ゴルフ、ホッケー、野球
電子メール: john@example.com
名前: フレッド
趣味: ホッケー
メールアドレス: fred@example.com
チーム
ゴルファー:
ジョン - john@example.com
ホッケー選手:
ジョン - john@example.com
フレッド - fred@example.com
野球選手:
ジョン - john@example.com