Insert Mysql query value in a comma-separated array

Asked

Viewed 77 times

1

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

I have this appointment:

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

This consultation results me this:

inserir a descrição da imagem aqui

I tried something like this:

    $Registros = array (
    ...
    );

I am trying to play these values in this comma separated array.

1 answer

2


Blz, here we come: From what I understand, your consultation and connection are okay. Just use the mysqli_fetch_array(), it has an array as the return type.

<?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 string with the query and the field identification type.

MYSQLI_ASSOC: -Voce can use column name to find data.

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

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

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

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

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

Browser other questions tagged

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