0

「while」で値を選択したいのですが、問題があります。これはコードです:

<?php 
$following_select_article = mysql_query("SELECT * FROM follow WHERE user_follower_id='$user_id'");

while( $following_select_article_row = mysql_fetch_array($following_select_article) ) {
    $article_following_user_id = $following_select_article_row['user_following_id'].",";
    $mmnnss = substr_replace($article_following_user_id, "", -1);
    $echo $mmnss;
}

ノート$user_id = 1

望ましい出力は

2,3,4

しかし、私が得るのは

234

db は次のようになります。

次の表:

ID | user_follower_id | user_following_id

1 | 1 | 2

2 | 1 | 4

3 | 1 | 3

ありがとう

4

1 に答える 1

2

これを行う

<?php 

$following_select_article = mysql_query("SELECT * FROM follow WHERE user_follower_id='$user_id'");
$article_following_user_id = "";
while($following_select_article_row = mysql_fetch_array($following_select_article)){

    $article_following_user_id .= $following_select_article_row['user_following_id'].",";

}
$mmnnss = substr_replace($article_following_user_id, "", -1);
echo $mmnnss;

あなたsubstr_replaceはループしているので、作成後は$article_following_user_id毎回,最後の文字を毎回置き換えます

編集

Glavićが提案したように、交換できる場合

substr_replace($article_following_user_id, "", -1);

substr($article_following_user_id, 0, -1);
于 2013-09-22T05:33:15.330 に答える