Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

266
Visualizações
Passing all MYSQL record into array with key and value formated

I'm selecting from MYSQL database and I need to pass all selected records to an array in the format like this: Array

(

    [1] => Weather today is rubbish
    [2] => This cake looks amazing
    [3] => His skills are mediocre
    [4] => He is very talented
    [5] => She is seemingly very agressive
    [6] => Marie was enthusiastic about the upcoming trip. Her brother was also passionate about her leaving - he would finally have the house for himself.
    [7] => To be or not to be?
)

I want the key to be autogenerated.and be assigned to each record.

Here us my code:

$conn = new mysqli($servername, $username, $password, $dbname);

$SQLCommand = "SELECT fback FROM feedback";

$result = mysqli_query($conn, $SQLCommand);

$i = 1; 
$query = mysqli_query($conn, 'SELECT fback FROM feedback');
$tot = mysqli_num_rows($query);
echo '<br/>You are having <b style="color:red;">' . $tot . '</b> tasks to do.<br/><br/>'; 
while($a = mysqli_fetch_array($query))
{   
     echo $i++ . '. ' . $a[0] . '<br/>';
}$featured = array();

foreach($featured as $key => $value){
  echo $a;
}
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Do you mean like that?

$featured = array();
$count = 1;
while($a = mysqli_fetch_array($query)) {   
     $featured[$count] = $a[0];
     $count++; 
}

print_r($featured);
over 4 years ago · Santiago Trujillo Relatório

0

$conn = new mysqli($servername, $username, $password, $dbname);
$i = 1; 
$query = mysqli_query($conn, 'SELECT fback FROM feedback');
$tot = mysqli_num_rows($query);
$results = mysqli_fetch_array($query);
echo '<br/>You are having <b style="color:red;">' . $tot . '</b> tasks to do.<br/><br/>'; 
$arr = []; // Your array
foreach($results as $value)
{   
    $arr[] = $value[0];
    echo $i++ . '. ' . $value[0] . '<br/>';
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda