0

My code is

$sql = 'select * from table;' $res = $connection->query($sql);
while($row = mysqli_fetch_row($res){'tackle output'};

to get an object

while($row = $res->fetch_object()){'tackle output'};

Question: what do I have to do to get an array of objects, so my output is thus

$data[$row[0]]= fetch_object();
2

3 Answers 3

2

try this one:

$data = array();
while($row = $res->fetch_object()){
      $data[] = $row;
}
Sign up to request clarification or add additional context in comments.

3 Comments

I need a rec id to be the array index. For use in, if(isset($data[$id})){do something}
put it like $data[$row->id] = $row;
@bluepinto you are welcome, i have answered your question, if its helpful to you please fill free to accept and UV answer
1

Use it like

$data = array();
while($row = $res->fetch_object()){
      $data[$row->id] = $row;
}

Comments

0

may you want to fetch all you can do this by http://php.net/manual/en/mysqli-result.fetch-all.php

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.