Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

264
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!