PHPの別のwhileループ内に次のwhileループがあります。
$selecty = mysql_query("SELECT * FROM followers WHERE userid='".$_SESSION['id']."'");
$rowsy = mysql_num_rows($selecty);
echo '<td>'. $table["username"]. '</td>';
echo '<td>';
while ($tables = mysql_fetch_assoc($selecty)) {
if($tables['followerid']!=$table['id']) {
echo '<a href="#" data-userid="'.$table['id'].'" class="follow">'.'</a>';
} else {
echo '<a href="#" data-userid="'.$table['id'].'" class="following">'.'</a>';
}
}
echo '</td>';
echo "<tr>";
これは論理的な問題であり、ネストされたwhileループが正しい方法であるかどうかです。私が言おうとしているのは、「userfollowerstable」の「followerid」がusersテーブルの「id」(前のループからのもの)と同じでない場合です-フォローボタンをエコーします。それ以外の場合は、次のボタンをエコーします。
これは、フォロワーテーブルにデータがある間は機能するファイルですが、何も表示されない場合(行がないため)-PHPでこれを実装するにはどうすればよいですか?また、「フォロワーテーブル」に行がない場合は、「フォロー」ボタンをエコーしますか?