我想内爆整数并将其作为逗号分隔的字符串回显。我已经花了将近三个小时了,但我无法正常工作。
我当前得到的输出是:


  104104,105104,105,106


代替:


  104,105,106


我检查了php论坛,并说要使用mysql_fetch_assoc来避免这种情况,但这是行不通的。如果有人有任何想法请帮助。我的PHP看起来像这样:

<?PHP

$user_name = "root";
$password = "";
$database = "testdb";
$server = "127.0.0.1";

$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);

if ($db_found)
{
$SQL = "SELECT TableA.c1 FROM TableA ";
$result = mysql_query($SQL);
     while ($db_field = mysql_fetch_assoc($result))
     {
     $itinarry[]= $db_field['c1'];
     $string = implode(',',$itinarry);
     echo $string;
     }
mysql_close($db_handle);

}
else
{
    echo "Database NOT Found ";
    mysql_close($db_handle);
 }

 ?>

最佳答案

它正在做的是

echo implode(",", array(104))

echo implode(",", array(104, 105))

echo implode(",", array(104, 105, 106))

结果是:

104104,105104,105,106



 $string = implode(',',$itinarry);
 echo $string;


while循环之外;

10-07 19:25