Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将数组中的数据保存到变量Moodle中_Php_Mysql_Arrays_Moodle - Fatal编程技术网

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
?>