Hey usually I use mysqli_fetch_array
to display the content of my database in my CMS, but recently someone told me I should use mysqli_fetch_assoc
and push the results into an array so that database only runs once instead of running the database for each record.
But I'm not really sure how to display my fields without showing them all, usually I would echo $data['field_name']
, but what I've noticed with mysqli_fetch_assoc
is I can't just echo $value['field_name']
, all I can do is echo $value
and it displays all the results.
This is what I've done, hope that makes sense. Thanks in advance for any help!
PHP
$sql = "SELECT * FROM app_categories";
if($result = query($sql)){
$list = array();
while($data = mysqli_fetch_assoc($result)){
array_push($list, $data);
}
foreach($list as $i=>$row){
foreach($row as $column=>$value){
echo $value;
}
}
}