Php 将数组中的数据保存到变量Moodle中
我试图将从数据库获取的数据显示为可读的格式,但我得到的是Php 将数组中的数据保存到变量Moodle中,php,mysql,arrays,moodle,Php,Mysql,Arrays,Moodle,我试图将从数据库获取的数据显示为可读的格式,但我得到的是 Array([1]=>stdClass对象([id]=>1[name]=>12[6]=>stdClass对象([id]=>6[name]=>Engineering学院[uni_id]=>13[7]=>stdClass对象([id]=>7[name]=>Engineering学院[uni_id]=>13])1当我使用echo print时($record) 代码 <?php $record= $DB->get_records_
Array([1]=>stdClass对象([id]=>1[name]=>12[6]=>stdClass对象([id]=>6[name]=>Engineering学院[uni_id]=>13[7]=>stdClass对象([id]=>7[name]=>Engineering学院[uni_id]=>13])1
当我使用echo print时($record)代码>
代码
<?php
$record= $DB->get_records_sql('SELECT * FROM {faculty}');
if($record != NULL)
{
echo print_r($record);
}
?>
如何将每列中的数据保存到变量中,以便以后在表中显示它们?您需要这样做(假设您的数组变量是$array
):-
您需要将其转换为普通数组,然后在该数组上进行迭代,也可以直接进行迭代。在Moodle中使用flexible_table。查看代码中的示例。谢谢,我已经理解了。:)
<?php
echo "<table><tr><th>ID</th><th>Name</th></tr><tbody>"; // start table
foreach($array as $arr){ // start iteration
echo "<tr><td>".$arr->id ."</td><td>".$arr->id ."</td></tr>"; // fetch value and set into table rows.
}
echo "</tbody></table>";//end table
?>