我想implode整數和echo它們作爲一個逗號分隔的字符串。我已經過了將近三個小時,並且無法工作。
我目前得到的輸出是:的Implode整數到mysql選擇語句(結果重複)
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);
}
?>
嘗試此'而($ db_field = mysql_fetch_assos($結果)){$ itinarry [] = array_values($ db_field); } $ string = implode(',',$ itinarry);'。將implode放置在循環之外。 – 2012-03-29 21:59:39