Save array to a php variable

Asked

Viewed 1,325 times

1

How to save all data from an array to a single variable ? example I call a query of a determianda column of the bank and Gero a while and wanted to put in a variable.

Maybe the right thing would be to join elements of a matrix into a string?

$sql_lista3 = mysql_query("select * from empresa as c1
                           inner join empresa_has_viagem as c2 on c1.em_id= c2.empresa_em_id
                           where viagem_via_id=37 order by viagem_via_id;"); 

while($resultado3 = mysql_fetch_array($sql_lista3)){
        $campanha = array($resultado3['em_nomefantasia']);
};

$resultado = implode(",", $campanha); //essa seria a variavel
  • What is the purpose of this code? $nada should get what? name sounds pretty intuitive :D

  • actually would be the result @rray

  • vc wants a string delimited by commas that?

  • You must receive data from a selected table.

  • That’s right @rray

  • 2

    Do so $campanha[] = $resultado3['em_nomefantasia']; see if that’s what you want.

  • that even correct friend thanks my faltering on not for $campaign[] maybe it has been lack of attention rs to sleepless days right kkk Valew bro.

  • To see the structure of an array use print_r($var), always takes away the doubts of how to use it.

  • Look who had done this and appeared only a company rs then I saw that I had error because it was more of a.

Show 4 more comments

1 answer

4

Change that code line of yours:

while($resultado3 = mysql_fetch_array($sql_lista3)){
    $campanha = array($resultado3['em_nomefantasia']);

};

For this:

while($resultado3 = mysql_fetch_array($sql_lista3)){
    $campanha[] = $resultado3['em_nomefantasia'];

};

Browser other questions tagged

You are not signed in. Login or sign up in order to post.