Insert mysql query value into a comma-separated array

1

I'm trying to insert a result of a query made in MySql into a comma-separated array, but I'm having trouble doing so.

I have this query:

SELECT 
  'gasUsuarioUnicoopSis'.IdUnicoop
FROM
  'gasUsuarioUnicoopSis'
WHERE
  ('gasUsuarioUnicoopSis'.IdUsuario = 3803) AND 
  ('gasUsuarioUnicoopSis'.IdSistema = 5)

This query gives me this:

I tried something like this:

    $Registros = array (
    ...
    );

I'm trying to throw these values into this comma-separated array.

    
asked by anonymous 12.12.2017 / 21:37

1 answer

2

Blz come on: From what I understand, your query and connection is ok. Just use mysqli_fetch_array (), it returns an array.

<?php
   $Conexao = mysqli_connect("localhost", "ServerUsuario", "ServerSenha");
   $Query = "SELECT 'gasUsuarioUnicoopSis'.IdUnicoop
             FROM 'gasUsuarioUnicoopSis'
             WHERE ('gasUsuarioUnicoopSis'.IdUsuario = 3803) 
             AND ('gasUsuarioUnicoopSis'.IdSistema = 5)";
   $Consulta = mysqli_query($Conexao, $Query);

   $Registros = mysqli_fetch_array($Consulta, MYSQLI_ASSOC));

To use the Array, simply declare the desired index. Echo () is just one of the possibilities.

mysqli_fetch_array () receives two parameters in its call: the query string and the field ID type.

MYSQLI_ASSOC: -You can use the column name to find data.

echo("Primeiro Campo:".$Registros[IdUsuario]. " Segundo Campo:". $Registros[IdSistema]);

MYSQLI_NUM: -> You can use a number to identify the index.

echo("Primeiro Campo:".$Registros[0]. " Segundo Campo:". $Registros[1]);

MYSQLI_BOTH: -> You can use both number and name.

echo("Primeiro Campo:".$Registros[IdUsuario]. " Segundo Campo:". $Registros[1]);
    
12.12.2017 / 21:53