从表中选择值并按时间显示


Select values from table and show it by while?

我想通过"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

数据库是这样的:

下表:

身份证 | user_follower_id | user_following_id

1 | 1 | 阿拉伯数字

2 | 1 | 四

3 | 1 | 3

谢谢

这样做

<?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后,它每次都会替换最后一个字符

编辑

正如格拉维奇所建议的那样,如果你可以更换你的

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

substr($article_following_user_id, 0, -1);