I want to implode integers and echo them as a comma separated string. I have been an this for almost three hours and I can’t get it to work.
The output I am currently getting is:
104104,105104,105,106
instead of:
104,105,106
I checked the php forums and it says to use mysql_fetch_assoc to avoid this but it doesn’t work. If anyone has any ideas please help. My PHP looks like this:
<?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);
}
?>
What it’s doing is
echo implode(",", array(104))echo implode(",", array(104, 105))echo implode(",", array(104, 105, 106))Which results in:
104104,105104,105,106Put
out side out the
whileloop;