私のテーブル「user_sightings」では、各ユーザーに複数のエントリを許可しているため、次のようになります...
------------------------
ID | user_ID | postcode
1 39 ab12cd
2 39 sk91ab
3 39 ab44ix
クエリを実行した後、次のように各郵便番号を印刷しようとします...
echo $row["postcode"];
これだけがそのユーザーの最初のインスタンスを出力するだけです。ユーザーのすべてのインスタンスを取得し、それらを変数として動的に設定する方法はありますか?
クエリ:
$sth = $conn->prepare("SELECT * FROM directory, user_sightings WHERE directory.user_active != '' AND directory.ID = :uid AND user_sightings.user_ID = :uid");
$sth->execute(array(':uid' => $UID));
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
echo $row["postcode"];
}