0

I am reading data from a Mysql database like this:

$result = mysqli_query($con,"SELECT * FROM myTable");

while($row = mysqli_fetch_array($result))
  {

  echo $row['field1'] . " " . $row['field2'];

  }

Instead of outputting the records like this:

 echo $row['field1'] . " " . $row['field2'];

I need to get them into the format below:

$list = array(

        array('field1'=>'something here', 'field2'=>'something else')

  );

How do I do this?

2
  • us2.php.net/manual/en/mysqli-result.fetch-array.php, there's an example of how to do exactly what you want, in the documentation for what you're using. Commented Apr 8, 2014 at 12:19
  • Don't even know what to say. What's wrong with $result[] = array('field1'=>$row['field1'], 'field2'=>$row['field2']) ? Commented Apr 8, 2014 at 12:20

1 Answer 1

2
$result = mysqli_query($con,"SELECT * FROM myTable");

while($row = mysqli_fetch_array($result)){

  $list[] = $row;

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.