I cannot solve this seeming simple problem. I have the following simple code and all I want is to echo the result of $ATL5_Alert_query and separated by a comma (,):

$ATL5_Alert_query = mysql_query("SELECT `Mobile` FROM `dbo_tech_name` WHERE `AlertLevel`= 1"); 

$dataset = array();
 while ($data = mysql_fetch_array($ATL5_Alert_query))
 {
   $dataset[] = $data;
 }
echo implode (",", $dataset);

However, I'm getting "Notice: Array to string conversion "...

share|improve this question
    
Can you try to inspect the variables and there types with var_dump()? I don't think it is a duplicate but it is related to stackoverflow.com/questions/20017409/… and stackoverflow.com/questions/6817148/… – Risadinha Jun 19 '15 at 8:09
up vote 1 down vote accepted

In your code $data is array as well, so $dataset becomes an array of arrays, which you cannot concatenate. You should get the searched value by this:

while ($data = mysql_fetch_array($ATL5_Alert_query))
{
   $dataset[] = $data['Mobile'];
}

or:

while ($data = mysql_fetch_array($ATL5_Alert_query))
{
   $dataset[] = $data[0];
}

or:

while ($data = mysql_fetch_assoc($ATL5_Alert_query))
{
   $dataset[] = $data['Mobile'];
}

If you however cannot change this, and already have your $dataset array, you can implode it like that:

echo implode(',', array_map(function($a){
  return $a['Mobile'];
},$dataset));
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.